Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Introduction to Physical Computing - ITP - NYU
// Fall 2013 - Tom Igoe
// Midterm Project - Color Flute
// Abe Rubenstein + Yu Ji
// ARDUINO
// global variables for raw sensor values
int photo1 = 0; // photoresistor 1 (red)
int photo2 = 0; // photoresistor 2 (green)
int photo3 = 0; // photoresistor 3 (blue)
int blow = 0; // piezo (blow)
int accX = 0; // accelerometer (x-axis)
int accY = 0; // accelerometer (y-axis)
// global variables for binarized photoresistor sensor values
int photo1Out = 0;
int photo2Out = 0;
int photo3Out = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
photo1 = analogRead(A0);
photo2 = analogRead(A1);
photo3 = analogRead(A2);
blow = analogRead(A3);
accX = analogRead(A4);
accY = analogRead(A5);
// Binarize the photoresistor values:
// 700 is the threshold point
// works well for most lighting situations
if (photo1 <= 700) photo1Out = 255;
if (photo2 <= 700) photo2Out = 255;
if (photo3 <= 700) photo3Out = 255;
if (photo1 > 700) photo1Out = 0;
if (photo2 > 700) photo2Out = 0;
if (photo3 > 700) photo3Out = 0;
printSensorData(0);
// Wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
}
void printSensorData(int debug) {
// Prints raw sensor values
if (debug) {
Serial.print(photo1);
Serial.print(" / ");
Serial.print(photo2);
Serial.print(" / ");
Serial.print(photo3);
Serial.print("\t output = ");
}
Serial.print(photo1Out);
Serial.print('/');
Serial.print(photo2Out);
Serial.print('/');
Serial.print(photo3Out);
Serial.print('/');
Serial.print(blow);
Serial.print('/');
Serial.print(accX);
Serial.print('/');
Serial.println(accY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment