SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define PIN_MODRA 3
  2. #define PIN_RDECA 4
  3. #define PIN_ZELENA 5
  4.  
  5. int r = 0;
  6. int g = 0;
  7. int b = 0;
  8.  
  9.  
  10. void setup() {
  11.   Serial.begin(9600);
  12.   // put your setup code here, to run once:
  13.  
  14. }
  15.  
  16. void loop() {
  17.  
  18.  
  19.   for(int temp=0; temp<35; temp++){
  20.     Serial.print("Temp: ");
  21.     Serial.println(temp);
  22.     int temp_mapped = map(temp, 0, 35, 0, 100);
  23.     Serial.print("Mapped: ");
  24.     Serial.println(temp_mapped);
  25.     if(temp_mapped <= 25){
  26.       r = 0;
  27.       g = map(temp_mapped, 0, 25, 0, 255);
  28.       b = 255;
  29.     }else if(temp_mapped > 25 && temp_mapped <= 50){
  30.       r = 0;
  31.       g = 255;
  32.       b = map(temp_mapped, 25, 50, 255, 0);
  33.     }else if(temp_mapped > 50 && temp_mapped <= 75){
  34.       r = map(temp_mapped, 50, 75, 0, 255);
  35.       g = 255;
  36.       b = 0;
  37.     }else if(temp_mapped > 75 && temp_mapped <= 100){
  38.       r = 255;
  39.       g = map(temp_mapped, 75, 100, 255, 0);
  40.       b = 0;
  41.     }
  42.    
  43.     set_led_strip_color(r, g, b);
  44.  
  45.     }
  46.  
  47.   Serial.println("****************************");
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. }
  57.  
  58.  
  59. void set_led_strip_color(int red, int green, int blue){
  60.   //red
  61.   analogWrite(PIN_RDECA, red);
  62.   Serial.print("Red: ");
  63.   Serial.println(red);
  64.   //green
  65.   analogWrite(PIN_ZELENA, green);
  66.   Serial.print("Green: ");
  67.   Serial.println(green);
  68.   //blue
  69.   analogWrite(PIN_MODRA, blue);
  70.   Serial.print("Blue: ");
  71.   Serial.println(blue);
  72.  
  73.   delay(1000);
  74.   Serial.println("-------------------------------");
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top