Advertisement
Guest User

lab 2

a guest
Apr 8th, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int LDR = 3;
  2. int laser = 4;
  3. boolean state = false;
  4. float lower=2.2;
  5. float upper=3.3;
  6. int a =0;
  7. void setup(){
  8.  pinMode(LDR,INPUT);
  9.  pinMode(laser,OUTPUT);
  10. }
  11.  
  12. void loop() {
  13.   //State A = flase , State B = true
  14.   int sensorValue  = analogRead(LDR);
  15.   float voltage = sensorValue * (5.0 / 1023.0);
  16.   //State A with input  X = 0 =---> Stay At A with output 0
  17.   if(voltage<lower && state==false ){
  18.      a=0;
  19.   }//State A with input X = 1 =---> Go to B with output 0
  20.   else if(voltage>upper && state==false){
  21.     state=true;
  22.   a=0;
  23.    
  24.   }//State B with input X = 0 =---> Stay at B with output 0
  25.   else if(voltage<lower && state==true){
  26.    a=0
  27.   }//State B with input X = 1 =---> Switch to A with output 1
  28.   else if(voltage>upper && state == true){
  29.     state=false;
  30.     a=1;
  31.   }
  32.   delay(30);
  33.   /*if(a==(output of the sensor of the other machine ))
  34.   {
  35.     true or false;
  36.   }*/
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement