Variable storing on Arduino uno


hello,


i want echosendrecievenorth/east/west read time takes till gets back, convert centimeters , store ncm/ecm/wcm. want read these values , make decision based on these values. after decision has been made want execute things, , rescan area. how store these value's? here code:

code: [select]
#include <servo.h>

int snorrechts = 6;
int snorlinks = 5;
int snorrechtsstaat = low;
int snorlinksstaat = low;
int ontvanger = 7;
int echo = 8;
long eduration, ecm;
long nduration, ncm;
long wduration, wcm;
int led = 13;

servo left;
servo right;
servo top;
void setup() {
  serial.begin(9600);
  top.attach(9);
  left.attach(11);
  right.attach(12);
  pinmode(snorrechts, input);
  pinmode(snorlinks, input);
  pinmode(echo, output);
  pinmode(ontvanger, input);
  pinmode(led, output);
  top.write(12);
      }

void loop() {
 
  eduration = pulsein(ontvanger, high);
  nduration = pulsein(ontvanger, high);
  wduration = pulsein(ontvanger, high);
 
  ecm = eduration/58.4;
  ncm = nduration/58.4;
  wcm = wduration/58.4;
 
  snorrechtsstaat = digitalread(snorrechts);
  snorlinksstaat = digitalread(snorlinks);

  right.write(202);
  left.write(18);
 
   
 /* if (cm <= 20){
   left.write(198);
   right.write(22);
   delay(1800);
   serial.println(cm);
   delay(100);
        }
  if (cm >= 20){

  right.write(202);
  left.write(18);
  delay(50);
  serial.println(cm);
  delay(100);
  //digitalwrite(led, low); */
  top.write(12);
  delay(1000);
  echosendrecieveeast();
  delay(100);
 
  top.write(102);
  delay(500);
  echosendrecievenorth();
  delay(100);
 
  top.write(192);
  delay(500);
  echosendrecievewest();
  delay(100);

  if (wcm <= 20 && ncm <= 20){
    delay(50);
    left.write(18);
    right.write(102);
    delay(890);
    right.write(202);
  }
 
  if (ecm <= 20 && ncm <= 20){
    delay(50);
    left.write(118);
    right.write(202);
    delay(970);
    left.write(18);
   
  }
 
 
  if(snorrechtsstaat == high) {
    delay(100);
    left.write(198);
    right.write(22);
    delay(2750);
    rechtsturn();
    linksturn();
 
 
}
 if(snorlinksstaat == high){
   delay(100);
   left.write(198);
   right.write(22);
   delay(2750);
   linksturn();
   rechtsturn();
 
 }
}
 

  void rechtsturn(){
  left.write(18);
  right.write(202);
  delay(750);
  right.write(102);
  //delay(3650);
  //delay(6850);
  delay(890.0);
  //left.write(108);
  //right.write(112);
  }
  void linksturn(){
  left.write(18);
  right.write(202);
  delay(750);
  left.write(118);
  delay(970);
  }
  void achtje(){
  right.write(202);
  left.write(103);
  delay(7200);
  left.write(18);
  delay(3000);
  right.write(117);
  delay(10000);
  right.write(202);
  delay(3000); }

  void echosendrecievewest(){
  digitalwrite(echo, low);
  delaymicroseconds(2);
 
  digitalwrite(echo, high);
  delaymicroseconds(11);
 
  digitalwrite(echo, low);
[s]  serial.println(wcm);[/s]
  delay(15);
    }
    void echosendrecievenorth(){
  digitalwrite(echo, low);
  delaymicroseconds(2);
 
  digitalwrite(echo, high);
  delaymicroseconds(11);
 
  digitalwrite(echo, low);
[s]  serial.println(ncm);[/s]
  delay(15);
    }
    void echosendrecieveeast(){
  digitalwrite(echo, low);
  delaymicroseconds(2);
 
  digitalwrite(echo, high);
  delaymicroseconds(11);
 
  digitalwrite(echo, low);
[s]  serial.println(ecm);[/s]
  delay(15);
    }


thanks help

you've got awful lot of code there doesn't know how assign simple variable.

what i'm trying if you're stuck, lot of @ few basic c++ tutorials , maybe few of example sketches come ide. 

what you're asking right analogous to...  "i gonna drive truck, steering wheel?" 

if want copy , paste way through writing code that's fine, don't expect able modify of in meaningful way.


Arduino Forum > Using Arduino > Project Guidance > Variable storing on Arduino uno


arduino

Comments