Advertisement
lekobh

4teclas 6leds

Jul 28th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.34 KB | None | 0 0
  1.  
  2.  
  3. // Teste leds + Teclado
  4. // Configurando os pinos:
  5.  
  6.     //LEDS
  7. const int leD6    =  8;      // the number of the LED pin
  8. const int leD5    =  9;      // the number of the LED pin
  9. const int leD4    =  10;      // the number of the LED pin
  10. const int leD3    =  11;      // the number of the LED pin
  11. const int leD2    =  12;      // the number of the LED pin
  12. const int leD1    =  13;
  13.    //Botoes
  14. const int K4      =  A0;     // the number of the pushbutton pin  
  15. const int K3      =  A1;     // the number of the pushbutton pin  
  16. const int K2      =  A2;     // the number of the pushbutton pin  
  17. const int K1      =  A3;     // the number of the pushbutton pin  
  18.  
  19.    //Energia Botoes
  20. const int tecl    =  A4;     // the number of the pushbutton pin  
  21.  
  22. // variables will change:
  23. int ledstate = LOW;         // variable for reading the pushbutton status
  24. unsigned long previousMillis = 0;
  25.  
  26. void setup() {
  27.     pinMode(leD1, OUTPUT);
  28.     pinMode(leD2, OUTPUT);
  29.     pinMode(leD3, OUTPUT);
  30.     pinMode(leD4, OUTPUT);
  31.     pinMode(leD5, OUTPUT);
  32.     pinMode(leD6, OUTPUT);
  33.    
  34.     pinMode(K1, INPUT);
  35.     digitalWrite(K1, HIGH);
  36.     pinMode(K2, INPUT);
  37.     digitalWrite(K2, HIGH);
  38.     pinMode(K3, INPUT);
  39.     digitalWrite(K3, HIGH);
  40.     pinMode(K4, INPUT);
  41.     digitalWrite(K4, HIGH);    
  42.  
  43.     pinMode(tecl, OUTPUT);
  44.    
  45.     digitalWrite(tecl, LOW);
  46.  
  47. }
  48.  
  49. void loop() {
  50.  
  51.     if (digitalRead(K1) == LOW) {
  52.     digitalWrite(leD1, HIGH);
  53.     }
  54.       else {
  55.          // turn LED off:
  56.          digitalWrite(leD1, LOW);
  57.     }  
  58.  
  59.       if (digitalRead(K2) == LOW) {
  60.     digitalWrite(leD2, HIGH);
  61.     }
  62.       else {
  63.          // turn LED off:
  64.          digitalWrite(leD2, LOW);
  65.     }  
  66.  
  67.       if (digitalRead(K3) == LOW) {
  68.     digitalWrite(leD3, HIGH);
  69.     }
  70.       else {
  71.          // turn LED off:
  72.          digitalWrite(leD3, LOW);
  73.     }  
  74.  
  75.  
  76.       if (digitalRead(K4) == LOW) {
  77.     digitalWrite(leD4, HIGH);
  78.     }
  79.       else {
  80.          // turn LED off:
  81.          digitalWrite(leD4, LOW);
  82.     }  
  83.  
  84.  
  85.    unsigned long currentMillis = millis();
  86.  
  87.   if(currentMillis - previousMillis >= 500) {
  88.     previousMillis = currentMillis;  
  89.  
  90.     if (ledstate == LOW)
  91.       ledstate = HIGH;
  92.     else
  93.       ledstate = LOW;
  94.  
  95.    digitalWrite(leD5, ledstate);
  96.    digitalWrite(leD6, !ledstate);
  97.    
  98.   }
  99.    
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement