Advertisement
Guest User

Moodtoy

a guest
Nov 20th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1. //LEDpins
  2. const int redLED = 9;
  3. const int greenLED = 10;
  4. const int blueLED = 11;
  5.  
  6. //LED info
  7. int redLevel = 0;
  8. int greenLevel = 0;
  9. int blueLevel = 0;
  10. float counter = 0;
  11. float pi = 3.14159;
  12.  
  13.  
  14. //SENSORpins
  15. const int HALL = 2;
  16. const int BALL = 3;
  17. const int LIGHT = 4;
  18.  
  19. //other ints
  20. int randomValue = 0;
  21. int brightness = 0;
  22. int fadeAmount = 2;
  23.  
  24. void setup(){
  25. //LEDpins
  26. pinMode(redLED, OUTPUT);
  27. pinMode(greenLED, OUTPUT);
  28. pinMode(blueLED, OUTPUT);
  29.  
  30. //Sensors
  31. pinMode(HALL, INPUT);
  32. pinMode(BALL, INPUT);
  33. pinMode(LIGHT, INPUT);
  34. }
  35.  
  36. //Start loop
  37. void loop()
  38. {
  39. int MOOD = random(100);
  40.  
  41.   if (MOOD <=3) {
  42.   // code for ANGRY here
  43.  
  44.    // set the brightness of pin RED:
  45.   analogWrite(redLED, brightness);
  46.  
  47.   // change the brightness for next time through the loop:
  48.   brightness = brightness + fadeAmount;
  49.  
  50.   // reverse the direction of the fading at the ends of the fade:
  51.   if (brightness <= 0 || brightness >= 255) {
  52.     fadeAmount = -fadeAmount;
  53.   }
  54.   // wait for 30 milliseconds to see the dimming effect
  55.   delay(30);
  56.  
  57.   if (digitalRead (BALL) == HIGH && digitalRead (LIGHT) == HIGH)
  58.   {
  59.      void loop();
  60.   }
  61.   }
  62.  
  63.    if (MOOD > 3 && MOOD <= 10) {
  64.     // code for CALM here
  65.    
  66.    analogWrite(greenLED, brightness);
  67.  
  68.   // change the brightness for next time through the loop:
  69.   brightness = brightness + fadeAmount;
  70.  
  71.   // reverse the direction of the fading at the ends of the fade:
  72.   if (brightness <= 0 || brightness >= 255) {
  73.     fadeAmount = -fadeAmount;
  74.   }
  75.   // wait for 30 milliseconds to see the dimming effect
  76.   delay(30);
  77.  
  78. if (digitalRead (BALL) == HIGH)
  79. {
  80.     void loop();
  81.   }
  82.  
  83.   if (MOOD > 10 && MOOD <= 20) {
  84.      // code for PLAY here
  85.  
  86.   analogWrite(blueLED, brightness);
  87.  
  88.   // change the brightness for next time through the loop:
  89.   brightness = brightness + fadeAmount;
  90.  
  91.   // reverse the direction of the fading at the ends of the fade:
  92.   if (brightness <= 0 || brightness >= 255)
  93.   {
  94.     fadeAmount = -fadeAmount;
  95.   }
  96.   // wait for 30 milliseconds to see the dimming effect
  97.   delay(30);
  98.  
  99. if (digitalRead (HALL) == HIGH)
  100. {
  101.     void loop();
  102.   }
  103.   else
  104.   {
  105.    
  106.   // code for blendColors here
  107.   counter = counter + 1;
  108. redLevel = sin(counter/255)*1000;
  109. greenLevel = sin(counter/255 + pi*2/3)*1000;
  110. blueLevel = sin(counter/255 + pi*4/3)*1000;
  111. redLevel = map(redLevel,-1000,1000,0,255);
  112. greenLevel = map(greenLevel,-1000,1000,0,255);
  113. blueLevel = map(blueLevel,-1000,1000,0,255);
  114. analogWrite(redLED,redLevel);
  115. analogWrite(greenLED,greenLevel);
  116. analogWrite(blueLED,blueLevel);
  117. delay(10);
  118.   }
  119. }
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement