sibee86

Kopdar Arduino

Mar 11th, 2016
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. char str;
  2.   const int buttonPin1 = 10;
  3.   const int buttonPin2 = 11;
  4.   const int buttonPin3= 12;
  5.   const int buttonPin4= 13;
  6.  
  7.   int buttonState1 = 0;
  8.   int buttonState2 = 0;
  9.   int buttonState3 = 0;
  10.   int buttonState4 = 0;
  11.  
  12. void setup() {
  13.   Serial.begin(9600);
  14.   pinMode(buttonPin1,INPUT);
  15.   pinMode(buttonPin2,INPUT);
  16.   pinMode(buttonPin3,INPUT);
  17.   pinMode(buttonPin4,INPUT);
  18.   pinMode(2,OUTPUT);
  19.   pinMode(3,OUTPUT);
  20.   pinMode(4,OUTPUT);
  21.   pinMode(5,OUTPUT);
  22.   pinMode(6,OUTPUT);
  23.   pinMode(7,OUTPUT);
  24.   pinMode(8,OUTPUT);
  25.   pinMode(9,OUTPUT);
  26.   }
  27.  
  28. void loop() {
  29.   if(Serial.available()>0)
  30.     {
  31.       str = Serial.read();
  32.       if(str =='A') digitalWrite(2,HIGH);
  33.       delay(500);
  34.       digitalWrite(2,LOW);
  35.       if(str =='B') digitalWrite(3,HIGH);
  36.       delay(500);
  37.       digitalWrite(3,LOW);
  38.       if(str =='C') digitalWrite(4,HIGH);
  39.       delay(500);
  40.       digitalWrite(4,LOW);
  41.       if(str =='D') digitalWrite(5,HIGH);
  42.       delay(500);
  43.       digitalWrite(5,LOW);
  44.       if(str =='E') digitalWrite(6,HIGH);
  45.       delay(500);
  46.       digitalWrite(6,LOW);
  47.       if(str =='F') digitalWrite(7,HIGH);
  48.       delay(500);
  49.       digitalWrite(7,LOW);
  50.       if(str =='G') digitalWrite(8,HIGH);
  51.       delay(500);
  52.       digitalWrite(8,LOW);
  53.       if(str =='H') digitalWrite(9,HIGH);
  54.       delay(500);
  55.       digitalWrite(9,LOW);
  56.       delay(500);
  57.      
  58.       buttonState1 = digitalRead(buttonPin1);
  59.       buttonState2 = digitalRead(buttonPin2);
  60.       buttonState3 = digitalRead(buttonPin3);
  61.       buttonState4 = digitalRead(buttonPin4);
  62.      
  63.       if (buttonState1 == 1);
  64.          Serial.write(1);
  65.          if (buttonState2 == 1);
  66.          Serial.write(2);
  67.            
  68.     }
  69.   // put your main code here, to run repeatedly:
  70.  
  71. }
Add Comment
Please, Sign In to add comment