weturtle

LedRGB_Fotoresistenza

Jan 13th, 2019
10,941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int Red = 3;
  2. const int Green = 4;
  3. const int Blue = 5;
  4.  
  5. void setup() {
  6.   pinMode(Red,OUTPUT);
  7.   pinMode(Green,OUTPUT);
  8.   pinMode(Blue,OUTPUT);
  9.   pinMode(A1,INPUT);
  10.  
  11.   Serial.begin(9600);
  12. }
  13.  
  14. void loop() {
  15.   int light;
  16.   light = analogRead(A1)/100;
  17.   if(light>8){
  18.     colora(200,150,150);
  19.   }else{
  20.     colora(255,0,0);
  21.   }
  22.  
  23. Serial.println(light);
  24.   delay(100);
  25. }  
  26.  
  27. void colora(int R, int G, int B){
  28.   analogWrite(Red, R);
  29.   analogWrite(Green, G);
  30.   analogWrite(Blue, B);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment