We are creating a ball that changes colour depending on its speed when it rolls.
I have a 3 axis accelerometer sensor.
This is the code we are using at the moment:
int xAxis = A3;
int yAxis = A1;
int zAxis = A2;
int axisValue = 0;
int led = 13;
int led2 = 12;
int led3 = 11;
void setup() {
Serial.begin(38400);
Serial.println("Starting up");
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop() {
axisValue = analogRead(xAxis);
Serial.print("X="); Serial.print(axisValue);
axisValue = analogRead(yAxis);
Serial.print(",Y="); Serial.print(axisValue);
axisValue = analogRead(zAxis);
Serial.print(",Z="); Serial.println(axisValue);
if (axisValue > 300 ) {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(led2, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(led3, LOW); // turn the LED on (HIGH is the voltage level)
Serial.println("more than 300");
}
else if (axisValue < 300 ) {
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(led2, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(led3, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.println("less than 300");
}
// delay(200);
}
So I have some LEDs that turn on and off. But I want to change the light according to speed not only to position. How can I do that?