Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. /* ===============
  2. Project #3!
  3. ================= */
  4.  
  5. //#include <Adafruit_NeoPixel.h>
  6. #include <Servo.h>
  7. #include <Wire.h>
  8. #include "Adafruit_TCS34725.h"
  9.  
  10. #define NEW_PIXEL_PIN 6
  11. #define NUMPIXELS 4
  12.  
  13. #define servoPin1 2
  14. #define servoPin2 3
  15.  
  16. /* Connect SCL to A5
  17. Connect SDA to A4
  18. */
  19.  
  20. //Adafruit_NeoPixel pixels(NUMPIXELS, NEW_PIXEL_PIN, NEO_GRB + NEO_KHZ800);
  21. Adafruit_TCS34725 tcs = Adafruit_TCS34725();
  22. Servo Servo1, Servo2;
  23.  
  24. uint16_t r, g, b, c, colorTemp, lux;
  25.  
  26. void setup() {
  27. Serial.begin(9600);
  28.  
  29. Serial.println("Starting!");
  30. // pixels.begin();
  31. Servo1.attach(servoPin1);
  32. Servo2.attach(servoPin2);
  33.  
  34. Serial.println(tcs.begin());
  35. if (tcs.begin()) {
  36. Serial.println("Found sensor");
  37. } else {
  38. Serial.println("No TCS34725 found ... check your connections");
  39. while (1);
  40. }
  41. }
  42.  
  43. void loop() {
  44. get_color();
  45.  
  46. if (r > 0) {
  47. servo(Servo1, 3);
  48. } else if (b > 0) {
  49. servo(Servo2, 3);
  50. } else { // green
  51. servo(Servo1, 3);
  52. servo(Servo2, 3);
  53. }
  54. delay(500);
  55. }
  56.  
  57. void servo(Servo servo, int times) {
  58. for (int i = 0; i < times; i++) {
  59. servo.write(i * 90);
  60. delay(500); //#1 sec delay
  61. }
  62. for (int i = times; i > 0; i--) {
  63. servo.write(i * 90);
  64. delay(500); //#1 sec delay
  65. }
  66. }
  67.  
  68. //void neo_pixel() {
  69. // pixels.clear();
  70. //
  71. // for (int i = 0; i < NUMPIXELS; i++) {
  72. //
  73. // pixels.setPixelColor(i, pixels.Color(0, 150, 0));
  74. // pixels.show();
  75. // delay(500);
  76. //
  77. // }
  78. //}
  79.  
  80. void get_color() {
  81. tcs.getRawData(&r, &g, &b, &c);
  82. colorTemp = tcs.calculateColorTemperature_dn40(r, g, b, c);
  83.  
  84. Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
  85. Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
  86. Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
  87. Serial.println(" ");
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement