I made a rgb led cube as my first project and added a IR remote. But im trying to make a led blink on a button press without delays. Any help is greatly appreciated. my code:
#include <IRremote.h>
#include <FastLED.h>
#define LED_PIN 2
#define NUM_LEDS 125
#define LED_TYPE WS2812
#define COLOR_ORDER RGB
#define IR_PEN 11
CRGB leds[NUM_LEDS];
int BRIGHTNESS = 150;
unsigned long Time;
unsigned long currentTime = 0;
int C = 0;
IRrecv IR(IR_PEN);
decode_results Resultaat;
void setup()
{
delay( 3000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
Serial.begin(9600);
IR.enableIRIn(); // Start IR-receiver
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB::Black;
}
FastLED.show();
}
void loop()
{
if (IR.decode(&Resultaat))
{
// if button 1 is pressed:
if(Resultaat.value == 0xFF30CF || Resultaat.value == 0x9716BE3F)
{
}
delay(100);
IR.resume();
}
// The code below works fine without using the IR remote.
// But i want to blink the button when the button is pressed.
Time = (millis() / 1000) % 60;
if(Time - currentTime >= 1)
{
currentTime = Time;
Blink(C);
C++;
if(C == 3)
C = 0;
}
}
void Blink(int c)
{
if(c == 0)
{
leds[0] = CRGB :: Black; FastLED.show();
}
if(c == 1)
{
leds[0] = CRGB :: White; FastLED.show();
}
if(c == 2)
{
leds[0] = CRGB :: Red; FastLED.show();
}
}
