The Accelerometer is driving the color of the led. The one thing that helped the most on this project was finding out the output voltages of the pins on the accelerometer. The Arduino reads from 0-5 volts and maps those values from 0-1024 I believe. But the accelerometer puts out a smaller range of voltages so you have to convert those to a broader range of values if you want your led to have a more drastic change in color. We did not connect capacitors to the outputs and i think that would have helped especially with the flickering you see in the video below.
void setup() {
Serial.begin(9600);
}
void loop() {
int xVal = analogRead(A2);
int yVal = analogRead(A1);
int zVal = analogRead(A0);
int red = 9;
int green = 10;
int blue = 11;
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
float rr = (xVal - 180.0) * (255.0 / 328.0);
float gg = (yVal - 180.0) * (255.0 / 328.0);
float bb = (zVal - 180.0) * (255.0 / 328.0);
analogWrite(red, rr);
analogWrite(green, gg);
analogWrite(blue, bb);
//Serial.println(xVal);
Serial.println(rr);
}

No comments:
Post a Comment