Hallo zusammen, bin an einen Projekt und zwar Dartscheibe an Arduino(Uno) , das auslesn der matrix klappt soweit ganz gut.
Die Dartscheibe ist mit 20 leds(WS2811) bestückt.
Wenn ein Wurf statt findet sollen die Leds bestimmte animationen abspielen, leider bleibt es hängen.
Jemand ne idee wie man das beheben kann?
#include "FastLED.h"
#define NUM_LEDS 20
#define PIN 14
CRGB strip[NUM_LEDS];
const byte numRows = 8;
const byte numCols = 8;
const int debounceTime = 100;
char keymap[numRows][numCols] = {
{'0','1','2','4','5','6','7','8'},
{'a','b','c','d','e','f','g','h'},
{'j','k','l','m','n','o','p','q'},
{'s','t','u','v','w','x','y','z'},
{'B','C','D','E','F','G','H','I'},
{'K','L','M','N','O','P','Q','R'},
{'T','U','V','W','X','Y','Z','+'},
{'*','/','?','!','&','
,'@','#'}
};
byte rowPins[numRows] = {13, 12, 11, 10, 9, 8, 7, 6};
byte colPins[numCols] = {5, 4, 3, 2, A5, A4, A3, A2};
void setup()
{
Serial.begin(9600);
FastLED.addLeds<WS2811, PIN, GRB>(strip, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(255);
FastLED.clear();
for (int row = 0; row < numRows; row++)
{
pinMode(rowPins[row],INPUT);
digitalWrite(rowPins[row],HIGH);
}
for (int column = 0; column < numCols; column++)
{
pinMode(colPins[column],OUTPUT);
digitalWrite(colPins[column],HIGH);
}
}
void loop()
{
char taster = wurf();
if( taster != 0) {
Serial.println(taster);
}
}
char wurf(){
char taster = 0;
for(int column = 0; column < numCols; column++){
digitalWrite(colPins[column],LOW);
for(int row = 0; row < numRows; row++){
if(digitalRead(rowPins[row]) == LOW ){
delay(debounceTime);
while(digitalRead(rowPins[row]) == LOW);
taster = keymap[row][column];
// S20
if(column == 1 && row == 4) {
set1( 10, 2, 100, 255, 255, 100);
}
}
}
digitalWrite(colPins[column],HIGH);
}
return taster;
}
void set1( byte start, byte off, byte r, byte g, byte b ,uint16_t warten)
{
static uint32_t previousMillis = 0;
static int8_t j = off - 1;
static byte d = 1;
strip[start + j] = CHSV(r, g, b);
strip[start - j] = CHSV(r, g, b);
FastLED.show();
strip[start + j] = CRGB::Black;
strip[start - j] = CRGB::Black;
if (millis() - previousMillis > warten){
if ((j >= off - 1) || (j < 1)) {
d = -d;
}
j += d;
previousMillis = millis();
}
}