Advertisement
makispaiktis

Arduino - Έλεγχος χρώματος LED από console

Apr 16th, 2019 (edited)
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define blue 3
  2. #define green 5
  3. #define red 6
  4.  
  5. char blueC = "b";
  6. char greenC = "g";
  7. char redC = "r";
  8.  
  9.  
  10. void setup() {
  11.   // put your setup code here, to run once:
  12.   pinMode(3, OUTPUT);
  13.   pinMode(5, OUTPUT);
  14.   pinMode(6, OUTPUT);
  15.   Serial.begin(9600);
  16.  
  17. }
  18.  
  19. void loop() {
  20.   // put your main code here, to run repeatedly:
  21.   char c;
  22.  
  23.   if(Serial.available()){
  24.     c = Serial.read();
  25.     if(c == 'r'){
  26.       analogWrite(red, 0);
  27.       analogWrite(blue, 255);
  28.       analogWrite(green, 255);
  29.     }else if(c == 'b'){
  30.       analogWrite(blue, 0);
  31.       analogWrite(red, 255);
  32.       analogWrite(green, 255);
  33.     }else if(c == 'g'){
  34.       analogWrite(green, 0);
  35.       analogWrite(blue, 255);
  36.       analogWrite(red, 255);
  37.     }else{
  38.       Serial.println();
  39.     }  
  40.   }
  41.  
  42.   delay(500);
  43.  
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement