Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.81 KB | None | 0 0
  1. int ButtonOne = A0;       // input pin one
  2. int ButtonTwo = A1;       // input pin two
  3. int ButtonThree = A2;     // input pin three
  4. int ButtonFour = A3;      // input pin four
  5. int ButtonOneValue = 0;   // variable to store button one instantaneous state
  6. int ButtonTwoValue = 0;   // variable to store button two instantaneous state
  7. int ButtonThreeValue = 0; // variable to store button three instantaneous state
  8. int ButtonFourValue = 0;  // variable to store button three instantaneous state
  9.  
  10. int LEDOnePin = 9;       // select the pin for the first LED strip
  11. int LEDTwoPin = 10;       // select the pin for the second LED strip
  12. int LEDThreePin = 11;     // select the pin for the third LED strip
  13. int LEDOneState = 0;      // variable to store the state of LED one
  14. int LEDTwoState = 0;      // variable to store the state of LED two
  15. int LEDThreeState = 0;    // variable to store the state of LED three
  16.  
  17. int counter = 0;          //test variable
  18.  
  19. void setup() {
  20.   Serial.begin(9600);          //  setup serial
  21.   // declare the LED pins as an OUTPUT:
  22.   pinMode(LEDOnePin, OUTPUT);
  23.   pinMode(LEDTwoPin, OUTPUT);
  24.   pinMode(LEDThreePin, OUTPUT);
  25.   pinMode(13, OUTPUT);
  26.   // turn the LED pins off:
  27.   digitalWrite(LEDOnePin, LOW);
  28.   digitalWrite(LEDTwoPin, LOW);
  29.   digitalWrite(LEDThreePin, LOW);
  30. }
  31.  
  32. void loop() {
  33.    
  34.   // read the value from the input pins:
  35.   ButtonOneValue = analogRead(ButtonOne);
  36.   ButtonTwoValue = analogRead(ButtonTwo);
  37.   ButtonThreeValue = analogRead(ButtonThree);
  38.   ButtonFourValue = analogRead(ButtonFour);
  39.   //delay 100ms to process input selection (fingers leaving buttons)
  40.   delay(200);
  41.   counter = counter + 1;
  42.   Serial.println(counter);             // debug value
  43.     // set output pin states
  44.     //do something only if there is an input
  45.   if ((ButtonOneValue > 1000) || (ButtonTwoValue > 1000) || (ButtonThreeValue > 1000) || (ButtonFourValue > 1000)){
  46.     // turn the led pin ON if input pin is HIGH / 5V and OFF if input is LOW / 0V
  47.     if(ButtonOneValue > 1000)
  48.     {
  49.       //Serial.println(ButtonOneValue);             // debug value
  50.       LEDOneOn();
  51.     }else{
  52.       LEDOneOff();
  53.     }
  54.     if(ButtonTwoValue > 1000)
  55.     {
  56.       LEDTwoOn();
  57.     }else{
  58.       LEDTwoOff();
  59.     }
  60.     if(ButtonThreeValue > 1000)
  61.     {
  62.       LEDThreeOn();
  63.     }else{
  64.       LEDThreeOff();
  65.     }
  66.     if(ButtonFourValue > 1000){
  67.      
  68.     }
  69.   }
  70.  
  71. }
  72.  
  73. void LEDOneOn(){
  74.   digitalWrite(LEDOnePin, HIGH);
  75.   LEDOneState=1;
  76. }
  77. void LEDTwoOn(){
  78.   digitalWrite(LEDTwoPin, HIGH);
  79.   LEDTwoState=1;
  80. }
  81. void LEDThreeOn(){
  82.   digitalWrite(LEDThreePin, HIGH);
  83.   LEDThreeState=1;
  84. }
  85. void LEDOneOff(){
  86.   digitalWrite(LEDOnePin, LOW);
  87.   LEDOneState=0;
  88. }
  89. void LEDTwoOff(){
  90.   digitalWrite(LEDTwoPin, LOW);
  91.   LEDTwoState=0;
  92. }
  93. void LEDThreeOff(){
  94.   digitalWrite(LEDThreePin, LOW);
  95.   LEDThreeState=0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement