Skip to content

Instantly share code, notes, and snippets.

@koji
Created September 26, 2016 21:40
Show Gist options
  • Save koji/19e64bba33726816519500473a7efc2e to your computer and use it in GitHub Desktop.
Save koji/19e64bba33726816519500473a7efc2e to your computer and use it in GitHub Desktop.
For Arduino
int rgbR = A0;
int rgbG = A1;
int rgbB = A2;
int mapR=0;
int mapG=0;
int mapB=0;
int r=0;
int g=0;
int b=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
r = analogRead(rgbR);
g = analogRead(rgbG);
b = analogRead(rgbB);
mapR = map(r,0,1023,0,255);
mapG = map(g,0,1023,0,255);
mapB = map(b,0,1023,0,255);
//Serial.print("R :");
//Serial.print(mapR);
//Serial.print(" G :");
//Serial.print(mapG);
//Serial.print(" B :");
//Serial.println(mapB);
Serial.print(mapR);
Serial.print(",");
Serial.print(mapG);
Serial.print(",");
Serial.println(mapB);
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment