Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define zielona 9
  2. #define czerwona 8
  3. String odebraneDane = "";
  4. boolean zielonaLow = true;
  5. boolean czerwonaLow = true;
  6. void setup() {
  7.   Serial.begin(9600); // uruchomienie komunikacji
  8.   pinMode(zielona, OUTPUT);
  9.   pinMode(czerwona, OUTPUT);
  10.  
  11.   digitalWrite(zielona, LOW);
  12.   digitalWrite(czerwona, LOW);
  13.  
  14.  
  15.  
  16. }
  17.  
  18. void loop() {
  19.   if (Serial.available() > 0) { // czy Arduino odebrało dane
  20.     odebraneDane = Serial.readStringUntil ('\n');
  21.     // Serial.println("Witaj " + odebraneDane + "!");
  22.     if (odebraneDane == "zielona" && zielonaLow == true) {
  23.  
  24.       digitalWrite(zielona, HIGH);
  25.       zielonaLow = false;
  26.      
  27.     } else  if (odebraneDane == "zielona" && zielonaLow == false) {
  28.       digitalWrite(zielona, LOW);
  29.       zielonaLow = true;
  30.      
  31.     } else    if (odebraneDane == "czerwona" && zielonaLow == true) {
  32.       digitalWrite(czerwona, HIGH);
  33.       czerwonaLow = false;
  34.  
  35.     } else    if (odebraneDane == "czerwona" && zielonaLow == false) {
  36.       digitalWrite(czerwona, LOW);
  37.       czerwonaLow = true;
  38.  
  39.     } else {
  40.       Serial.println("Błędny kolor");
  41.     }
  42.  
  43.   }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement