Hi, i am trying to switch between sequences in this program, i intend to use it in a garden lighting project, i have used MIT app inventor and generated an app on my android phone.
Programming is not my strong point so please forgive me, the code is as follows, it works but for some reason when i operate the relay via my phone i get a quick flash of an led on my Nano so i know the signal has been received.
The relay is taking up to 4 seconds plus to react....... i tried to do the same job with a transistor and i also tried with an optical relay but my novice ability is not good enough to make it work.
I tried to do it direct with the arduino, no mechanical intervention but i could not make it work, i am sure someone has seen this code before, i am switching 38 WS2812 led's, putting pin 2 to ground to switch between lighting effects.
Any help will be greatly received.
#include "FastLED.h"
#include <EEPROM.h>
#define NUM_LEDS 38
CRGB leds[NUM_LEDS];
#define PIN 6
#define BUTTON 2
byte selectedEffect=0;
int relay=9;
int Received=0;
int relay_state = 0;
void setup()
{
Serial.begin(9600);
pinMode(relay,OUTPUT);
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
pinMode(2,INPUT_PULLUP); // internal pull-up resistor
attachInterrupt (digitalPinToInterrupt (BUTTON), changeEffect, CHANGE); // pressed
}
void loop() {
if(Serial.available()>0)
{
Received = Serial.read();
}
EEPROM.get(0,selectedEffect);
if(selectedEffect>18) {
selectedEffect=0;
EEPROM.put(0,0);
}
if (relay_state == 0 && Received == '6')
{
digitalWrite(relay,HIGH);
relay_state=1;
Received=0;
}
delay(1000);
{
digitalWrite(relay,LOW);
relay_state=0;
Received=0;
}
switch(selectedEffect) {
case 0 : {
// RGBLoop - no parameters
RGBLoop();
break;
}