Wesley_Alves

Tamagoshi w/ Arduino

Apr 8th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. const byte BT[] = {13, 12, 11, 10};
  2. const unsigned long TEMPO[] = {1000, 2000, 3000, 4000};
  3. const String STATUS[] = {"FOME", "SONO", "IRRITADO", "DOENTE"};
  4.  
  5. void setup () {
  6.  
  7.   for (byte i = 0; i < 4; i++) {
  8.     pinMode(BT[i], OUTPUT);
  9.   }
  10.  
  11.   Serial.begin (9600);
  12. }
  13.  
  14. void loop () {
  15.   unsigned long tatual = millis ();
  16.   static unsigned long t0[] = {0, 0, 0, 0};
  17.  
  18.   static byte i = 0;
  19.   if (i >= 4) i = 0;
  20.  
  21.   if (digitalRead(BT[i])) {
  22.     Serial.println("NORMAL");
  23.     t0[i] = tatual;
  24.   } else if (tatual - t0[i] >= TEMPO[i]) {
  25.     Serial.println(STATUS[i]);
  26.   }
  27.   i++;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment