Hey everyone i need help with this code.
The interrupt is not working in setup and at the end: br_set
The code is from here: Updated cloud code. Patterns should play on button press. Β· GitHub
but I am adding some new functions to it.
Thanks for helping.
//import the necessary libraries
#include "FastLED.h"
#include "IRremote.h"
//define some variables
const int PW = 9;
const int PW_LED = 13;
int BR = 90;
const int BR_LED = 10;
#define LEDPIN 7
#define RECV_PIN 3
#define LED_TYPE WS2812
#define NUM_LEDS 300
CRGB leds[NUM_LEDS];
CRGB endclr;
CRGB midclr;
//set up IR receiver information
IRrecv irrecv(RECV_PIN);
decode_results results;
//<ββββββββββββββββββββββββββββSETUPββββββββββββββββββββββββββββ>
void setup() {
pinMode(PW_LED, OUTPUT);
pinMode(BR_LED, OUTPUT);
pinMode(PW, OUTPUT);
pinMode(RECV_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(RECV_PIN),br_set, CHANGE);
Serial.begin(9600);
delay(300);
irrecv.enableIRIn();
//set up LED strip information
FastLED.addLeds<LED_TYPE,LEDPIN>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BR);
}
//<βββββββββββββββββββββββββLOOPβββββββββββββββββββββββββββββββ>
void loop() {
FastLED.setBrightness(BR);
//decode IR results
if (irrecv.decode(&results)) {
//declare changing variables
uint8_t gHue = 0;
uint8_t colour = beatsin8(130, 0, 150);
uint8_t spd = beatsin8(10,0,255);
uint8_t dot = beatsin8(50, 0, NUM_LEDS);
uint8_t beat = beatsin8( 70, 64, 255);
uint8_t beat2 = beatsin8( 50, 64, 255);
//<ββββββββββββββββββBUTTON FUNCTIONSβββββββββββββββββββββββββ>
//power button = ON/OFF
if (results.value == 0xFFA25D)
{
digitalWrite(PW, HIGH);
digitalWrite(PW_LED, HIGH);
}
else{
digitalWrite(PW, LOW);
digitalWrite(PW_LED, LOW);
}
delay(25);
//vol+ = brightness up
FastLED.setBrightness(BR);
FastLED.show();}
}
//vol- = brightness down
if (results.value == 0xFD906F){
FastLED.setBrightness(BR);
FastLED.show();}
//play/pause = cycles through colour list
if (results.value == 0xFDA05F) {
fill_solid(leds, NUM_LEDS, CHSV(colour, 255, 150));
}
//left = CUSTOM GRADIENT (goes from a blue-purple gradient to pink-green. change the colour names below for a new pattern)
if (results.value == 0xFF22DD) {
endclr = blend(CRGB::Blue, CRGB::Pink, spd);
midclr = blend(CRGB::Purple, CRGB::Green, spd);
fill_gradient_RGB(leds, 0, endclr, NUM_LEDS/2, midclr);
fill_gradient_RGB(leds, NUM_LEDS/2+1, midclr, NUM_LEDS, endclr);
FastLED.show();}
//right = CUSTOM SOLID COLOUR (change colour name below to your favourite colour!)
if (results.value == 0xFD609F) {
fill_solid(leds,NUM_LEDS,CRGB::Purple);
}
//func/stop = xmas
if (results.value == 0xFFE21D) {
leds[dot] = CRGB::Red;
leds[dot+1] = CRGB::Green;
}
//up = bpm
if (results.value == 0xFD50AF) {
CRGBPalette16 palette = PartyColors_p;
for( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));}
}
//down = fire
if (results.value == 0xFD10EF) {
CRGBPalette16 palette = HeatColors_p;
for( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette(palette, gHue+(i*2), beat2-gHue+(i*10)); }
}
//eq = rainbow
if (results.value == 0xFDB04F) {
fill_rainbow( leds, NUM_LEDS-3, gHue, 7);
leds[12] = CRGB::Blue;
leds[13] = CRGB::Purple;
leds[14] = CRGB::Purple;
}
//st/rept = rainbow w stars
if (results.value == 0xFD708F) {
fill_rainbow( leds, NUM_LEDS-3, gHue, 7);
leds[12] = CRGB::Blue;
leds[13] = CRGB::Purple;
leds[14] = CRGB::Purple;
addGlitter(70);
}
// 0 = sun
if (results.value == 0xFD30CF) {
endclr = blend(CRGB::Yellow, CHSV(0,0,170), spd);
midclr = blend(CHSV(0,0,150), CRGB::Yellow, spd);
fill_gradient_RGB(leds, 0, endclr, NUM_LEDS/2, midclr);
fill_gradient_RGB(leds, NUM_LEDS/2+1, midclr, NUM_LEDS, endclr);
}
// 1 = sunrise (pink & blue)
if (results.value == 0xFD08F7) {
fill_gradient(leds, 0, CHSV(160,185,210), NUM_LEDS-1, CHSV(237,141,255));
}
// 2 = sunset (orange & blue)
if (results.value == 0xFD8877) {
fill_gradient_RGB(leds, 0, CHSV(150,255,200), NUM_LEDS-1, CHSV(25,255,255));
}
// 3 = sunrise to sunset
if (results.value == 0xFD48B7) {
endclr = blend(CHSV(150,255,210), CHSV(160,185,200), spd);
midclr = blend(CHSV(25,255,255), CHSV(237,141,255), spd);
fill_gradient_RGB(leds, 0, endclr, NUM_LEDS/2, midclr);
fill_gradient_RGB(leds, NUM_LEDS/2+1, midclr, NUM_LEDS, endclr);
}
// 4 = dusk
if (results.value == 0xFD28D7) {
fill_gradient_RGB(leds, 0, CHSV(160,255,150), NUM_LEDS-1, CHSV(180,230,80));
}
// 5 = starry night
if (results.value == 0xFDA857) {
fill_gradient_RGB(leds, 0, CHSV(160,255,150), NUM_LEDS-1, CHSV(180,230,80));
addGlitter(80);
}
// 6 = rain
if (results.value == 0xFD6897) {
fadeToBlackBy( leds, NUM_LEDS, 30);
int pos = random16(NUM_LEDS);
leds[pos] = CHSV(135,80,200);
}
// 7 = acid rain
if (results.value == 0xFD18E7) {
fadeToBlackBy( leds, NUM_LEDS, 130);
int pos = random16(NUM_LEDS);
leds[pos] = CRGB::Green;
}
// 8 = snow
if (results.value == 0xFD9867) {
fadeToBlackBy( leds, NUM_LEDS, 30);
addGlitter(50);
}
// 9 = storm
if (results.value == 0xFD58A7) {
fadeToBlackBy( leds, NUM_LEDS, 30);
fill_solid(leds,NUM_LEDS,CHSV(0,0,50));
addGlitter(60);
lightning();
}
//rotating base colour used by many of the patterns
FastLED.delay(1000/120);
EVERY_N_MILLISECONDS( 20 ) { gHue++; }
FastLED.show();
irrecv.resume(); // Receive the next value
}
}
//<ββββββββββββββββββββββBRIGHTNESSββββββββββββββββββββ>
void br_set(){
while(irrecv.decode(&results)){
if (results.value == 0xFF629D)
{
BR += 30;
delay(20);
}
if (results.value == 0xFFA857)
{
BR -= 30;
delay(20);
}
{
if (BR > 255 == true)
{
BR = 255;
}
if (BR < 0 == true)
{
BR = 0;
}
if (BR == 255 || BR == 0)
{
digitalWrite(BR_LED,HIGH);
}
else{
digitalWrite(BR_LED,LOW);
}
}
}
}
irrecv.resume(); // Receive the next value