#include #include #define LED_R 8 #define LED_G 7 #define LED_B 3 #define SW 2 #define TXD 0 #define RXD 1 #define DUR 500 #define NUM_LEDS 30 tinyNeoPixel pixels = tinyNeoPixel(NUM_LEDS, RXD, NEO_GRB + NEO_KHZ800); //SoftwareSerial mySerial(TXD, RXD); // RX, TX word sensorValue = 0; word R, G, B, minVal, maxVal; int setR, setG, setB; long tmp; void setup() { // put your setup code here, to run once: pinMode(LED_R, OUTPUT); pinMode(LED_G, OUTPUT); pinMode(LED_B, OUTPUT); pinMode(SW, INPUT); // set pin to input digitalWrite(SW, HIGH); digitalWrite(LED_R, HIGH); digitalWrite(LED_G, HIGH); digitalWrite(LED_B, HIGH); // mySerial.begin(38400); pixels.begin(); } void loop() { // put your main code here, to run repeatedly: // while (analogRead(SW) > 20) {} // key realesed // while (analogRead(SW) < 20) {} // key pressed R = 0; G = 0; B = 0; for (int i = 0; i < 2; i++) { digitalWrite(LED_R, LOW); delayMicroseconds(DUR); sensorValue = analogRead(SW); digitalWrite(LED_R, HIGH); delayMicroseconds(DUR); R += abs(analogRead(SW) - sensorValue); digitalWrite(LED_G, LOW); delayMicroseconds(DUR); sensorValue = analogRead(SW); digitalWrite(LED_G, HIGH); delayMicroseconds(DUR); G += abs(analogRead(SW) - sensorValue); digitalWrite(LED_B, LOW); delayMicroseconds(DUR); sensorValue = analogRead(SW); digitalWrite(LED_B, HIGH); delayMicroseconds(DUR); B += abs(analogRead(SW) - sensorValue); } // white ballance R = R * 6 / 11; G = G * 6 / 6; B = B * 6 / 7; // R = R / 4; // G = G / 4; // B = B / 4; //minVal 60 ... no sig minVal = min(min(R, G), B); R -= minVal; G -= minVal; B -= minVal; maxVal = max(max(R, G), B); if (maxVal > 40) { R = (long)R * 255 / maxVal; G = (long)G * 255 / maxVal; B = (long)B * 255 / maxVal; setR = (long)(3 * setR + R) / 4; setG = (long)(3 * setG + G) / 4; setB = (long)(3 * setB + B) / 4; // mySerial.print("R "); // mySerial.print(R); // mySerial.print(" G "); // mySerial.print(G); // mySerial.print(" B "); // mySerial.println(B); // } // else { // R = 0; // G = 0; // B = 0; } // analogWrite(LED_R, 255 - setR); // analogWrite(LED_G, 255 - setG); // analogWrite(LED_B, 255 - setB); // delay(20); // mySerial.write(1); // mySerial.write(2); // mySerial.write(3); // mySerial.write(4); // mySerial.write(R); // mySerial.write(G); // mySerial.write(B); // mySerial.write(setR); // mySerial.write(setG); // mySerial.write(setB); // // for(int i=0;i=0;i--){ pixels.setPixelColor(i+1, pixels.getPixelColor(i)); } pixels.setPixelColor(0, pixels.Color(setR,setG,setB)); delay(10); pixels.show(); }