I've created a very basic POV project.
It has a 12V DC motor with a piece of wood on it. The wood has 6 LEDs on it as well as a copper ring. The power is delivered to the LEDs from brushes connecting to the copper ring and from the shaft of the motor (the ground is attached to the base of the motor.) I'm using a TCRT5000L Sensor to count the RPM and have attached the LEDs to pin 13 and ground of the Arduino. (I've attached white tape to one side of the wood so that the sensor only counts one rev.)
I need help (please) with the program.
This is the code that I am using:
int pin = 13;
volatile int tcnt = 0;
volatile int lastcount = 0;
volatile int state = LOW;
void setup() {
Serial.begin(9600);
pinMode(pin, OUTPUT);
attachInterrupt(1, blink, RISING);
}
void loop() {
Serial.println(tcnt);
if (tcnt != lastcount)
{
digitalWrite(pin, HIGH);
delay(10);
digitalWrite(pin, LOW);
delay(10);
lastcount = tcnt;
}
delay(10);
}
void blink() {
tcnt = tcnt + 1;
state = !state;
}
My first issue is that the when I use the code above, the lights don't seem to switch on / off on the exact same area. They are within 30 degrees but certainly not precise.
The second issue (and the biggest) is that I'm sure that this code is not the best way to do what I need. For example, if I wanted to use this as an analog clock, so that the lights would only show on the current hour / minute, how would I do this?
Any help is greatly appreciated.