Download button at the bottom.
This is a program we created for the LED strip display course.
#include <Adafruit_NeoPixel.h>
#define LED_COUNT 20
#define StripPin A2
#define HallEffectSensorPin 6
#define HallEffectGNDPin 5
#define HallEffectVCCPin 4
int startSeconds = 20;
int startMinutes = 10;
int startHours = 1;
int secondsArrow;
int minutesArrow;
int hoursArrow;
int arrowPosition;
int hallSensorPastState = LOW;
int hallSensorRead;
int timeForOneRotation = 1;
unsigned long RPMTimer = millis();
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_COUNT, StripPin, NEO_GRB + NEO_KHZ800);
int color[3] = {255, 100, 150};
int secondsColor[3] = {255, 0, 0};
int minutesColor[3] = {0, 255, 0};
int hoursColor[3] = {0, 0, 255};
void setup(){
pinMode(HallEffectSensorPin, INPUT);
pinMode(HallEffectGNDPin, OUTPUT);
pinMode(HallEffectVCCPin, OUTPUT);
digitalWrite(5, LOW);
digitalWrite(HallEffectVCCPin, HIGH);
leds.begin();
leds.setPixelColor(19, color[0], Color[1], color[2]);
}
void loop(){
RPMUpdate();
ClearLedsWithoutTheLastOne();
arrowPosition = StateFrom60();
secondsArrow = ((int) floor(( millis() / 1000) + startSeconds) % 60);
minutesArrow = ((int) floor(( millis() / 60000) + startMinutes) % 60);
hoursArrow = ((int) floor(( millis() / 3600000) + startHours) % 12) * 5;
if (arrowPosition == secondsArrow){
for (int i = 0; i < LED_COUNT - 3; i ++){
leds.setPixelColor(i, secondsColor[0], secondsColor[1], secondsColor[2]);
}
}
if (arrowPosition == minutesArrow){
for (int i = 0; i < LED_COUNT - 6; i ++){
leds.setPixelColor(i, minutesColor[0], minutesColor[1], minutesColor[2]);
}
}
if (arrowPosition == hoursArrow){
for (int i = 0; i < LED_COUNT - 10; i ++){
leds.setPixelColor(i, hoursColor[0], hoursColor[1], hoursColor[2]);
}
}
if (arrowPosition % 5 == 0){
leds.setPixelColor(18, color[0], color[1], color[2]);
leds.setPixelColor(17, color[0], color[1], color[2]);
}
leds.show();
}
void RPMUpdate(){
hallSensorRead = digitalRead(HallEffectSensorPin);
if(hallSensorRead != hallSensorPastState){
if(hallSensorRead == HIGH){
timeForOneRotation = millis() - RPMTimer;
RPMTimer = millis();
hallSensorPastState = HIGH;
}
else{
hallSensorPastState = LOW;
}
}
}
void ClearLedsWithoutTheLastOne(){
for(int i = 0; i < LED_COUNT - 1; i ++){leds.setPixelColor(i, 0);}
}
int StateFrom60(){
return (int)floor(((millis() - RPMTimer) * 60) / timeForOneRotation) % 60;
}