This commit is contained in:
Lurkars 2020-12-28 19:15:19 +01:00
parent 60a76d10a1
commit c22afeba26

View File

@ -1,31 +1,89 @@
#include <FastGPIO.h>
#define APA102_USE_FAST_GPIO
#include <APA102.h>
const int HALL_PIN = 2;
const int ROUND_COUNT = 2;
void setup() {
// Define which pins to use.
const uint8_t dataPin = 10;
const uint8_t clockPin = 11;
// Create an object for writing to the LED strip.
APA102<dataPin, clockPin> ledStrip;
const uint16_t ledCount = 56;
const uint8_t brightness = 1;
const rgb_color RED = rgb_color(255, 0, 0);
const rgb_color GREEN = rgb_color(0, 255, 0);
const rgb_color BLUE = rgb_color(0, 0, 255);
const rgb_color WHITE = rgb_color(255, 255, 255);
const int state_count = 4;
rgb_color colors[ledCount];
float passed = 0;
int state = 0;
void setup()
{
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(HALL_PIN, INPUT);
}
void loop() {
void loop()
{
float start = micros();
int count = 0;
bool change = false;
while (count < ROUND_COUNT) {
if (digitalRead(HALL_PIN) == LOW) {
if(!change) {
while (count < ROUND_COUNT)
{
if (digitalRead(HALL_PIN) == LOW)
{
if (!change)
{
change = true;
count++;
}
} else {
}
else
{
change = false;
}
float current_diff = micros() - start;
for (int i = 0; i < state_count; i++)
{
if (current_diff > ((passed / state_count) * i))
{
state = i;
}
}
float end = micros();
float passed = (end - start);
Serial.print("Diff: ");
Serial.print(passed);
Serial.println("micro seconds");
rgb_color color = WHITE;
switch (state)
{
case 1:
color = RED;
break;
case 2:
color = GREEN;
break;
case 3:
color = BLUE;
break;
}
for (uint16_t i = 0; i < ledCount; i++)
{
colors[i] = color;
}
ledStrip.write(colors, ledCount, brightness);
}
passed = (micros() - start);
}