Hi , I'm having problems in which I can't figure out what is happening.
I have:
-
2 arduino uno's both equipped with an RF 315 shield. (RF_Shield_315MHz__SKU_TEL0075_-DFRobot)
-
One 315MHz remote
-
Neopixel 24 ring hooked up to Pin 6 for each arduino Uno.
When I get it all hooked up with the arduino on 5v and the neopixel on 5v I can only get a change in state when I get really close with the remote to the arduino unit. When I remove the Neopixels from Pin 6 on each unit and read out the serial. I get the proper inputs and can read them out.
I asked one fellow student who said it could be the interrupt that could conflict with the interrupt in the Neopixel library.
What should I do to go past the interrupt? And is it the interrupt? Below is my code:
//These are the libraries required.
//The adafruit Neopixel is for controlling the LED's.
//The HSBColor is for controlling the colors in Hue, Saturation and Brightness.
#include <Adafruit_NeoPixel.h>
#include <HSBColor.h>
//This is the PIN to
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);
#define DEFAULT_LED_SPEED 2800
#define MIN_LED_SPEED 5000
#define MAX_LED_SPEED 500
#define DEFUALT_LED_SATURATION 99
#define DEFAULT_LED_BRIGHTNESS 99
#define MAX_LED_SATURATION 99
const int saturationStep = 20;
long interval = 500; // interval at which to blink (milliseconds)
long intervalUp = 3000;
long intervalDown = 12000;
long previousMillis = 0; // will store last time LED was updated
int maxBrightness = 99;
int minBrightness = 0;
int stepDirection = 1;
// getRGB function stores RGB values in this array
// use these values for the red, blue, green led.
int rgb_colors[3];
int hue;
volatile int saturation = 0;
volatile int brightness = DEFAULT_LED_BRIGHTNESS;
volatile int ledSpeed = DEFAULT_LED_SPEED;
volatile boolean finalColor = false;
volatile boolean resetCycle = false;
const int ledSpeedPlus = 500;
volatile int buttonOne;
volatile int buttonTwo;
volatile int buttonThree;
volatile int buttonFour;
volatile int state = LOW;
int prevLedSaturation = DEFUALT_LED_SATURATION;
// blinkred parameters
int blackTime = 50;
int redTime = 100;
/The following 4 pin definitions,correspond to 4 buttons on the remote control(The telecontroller is Remote Wireless Keynob 315MHz(SKU:FIT0355))/
int D1 = 11; //The digital output pin 1 of decoder chip(SC2272)
int D2 = 9; //The digital output pin 2 of decoder chip(SC2272)
int D3 = 8; //The digital output pin 3 of decoder chip(SC2272)
int D4 = 10; //The digital output pin 4 of decoder chip(SC2272)
int redColor = 255;
int greenColor = 127;
int blueColor = 127;
int previousColor;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
/The four pins order below correspond to the 4 buttons on the remote control./
pinMode(D4, INPUT); //Initialized to input pin, in order to read the level of the output pins from the decoding chip
pinMode(D2, INPUT);
pinMode(D1, INPUT);
pinMode(D3, INPUT);
attachInterrupt(1,blink,RISING); //Digital pin 3,interrupt 1,corresponds to receiving interrupt pin of the decoding chip
Serial.println("Im Alive!!");
strip.begin();
strip.show();
simpleSetColorWhite();
}
void blink()
{
checkPins();
state = HIGH;
}
int programState = 0;
boolean showPeak = false;
void loop() {
// put your main code here, to run repeatedly:
// loop that reacts on button changes
if (state != LOW) {
state = LOW;
// if (saturation > prevLedSaturation) {
// nu moeten we een piekje laten zien
// showPeak = true;
// } else {
// showPeak = false;
// }
// prevLedSaturation = saturation;
if (buttonThree) {
resetAllParams();
simpleSetColorWhite();
}
calculateUpDownSpeed();
// show the button states
printButtons();
}
if (showPeak) {
// excecute peak code
// blinkRED();
showPeak = false;
}
if (!showPeak) {
fadeLoop(saturation);
}
}
void calculateUpDownSpeed() {
intervalUp = ledSpeed;
intervalDown = 4*ledSpeed;
}
void checkPins() {
delay(1);
buttonOne = digitalRead(D1);
buttonTwo = digitalRead(D2);
buttonThree = digitalRead(D3);
buttonFour = digitalRead(D4);
if (buttonOne) {
if (ledSpeed > MAX_LED_SPEED) {
ledSpeed += ledSpeedPlus;
ledSpeed = constrain(ledSpeed, MAX_LED_SPEED, MIN_LED_SPEED);
}
if (saturation > 0) {
saturation -= saturationStep;
saturation = constrain(saturation,0,MAX_LED_SATURATION);
}
}
if(buttonTwo){
if (ledSpeed < MIN_LED_SPEED) {
ledSpeed -= ledSpeedPlus;
ledSpeed = constrain(ledSpeed, MAX_LED_SPEED, MIN_LED_SPEED);
}
if (saturation < MAX_LED_SATURATION)
{
saturation += saturationStep;
saturation = constrain(saturation,0,MAX_LED_SATURATION);
}
}
if(buttonThree) {
finalColor != finalColor;
ledSpeed = 3000;
}
if(buttonFour) {
resetCycle != resetCycle;
}
}
void simpleSetColor(int current_color_saturation){
int tempArray[3];
H2R_HSBtoRGB(0, current_color_saturation, DEFAULT_LED_BRIGHTNESS, tempArray);
uint32_t strip_color = strip.Color(tempArray[0], tempArray[1], tempArray[2]);
for (int j=0; j<strip.numPixels(); j++) {
strip.setPixelColor(j, strip_color);
}
strip.show();
}
void simpleSetColorBlack(){
uint32_t strip_color = strip.Color(0, 0, 0);
for (int j=0; j<strip.numPixels(); j++) {
strip.setPixelColor(j, strip_color);
}
strip.show();
}
void simpleSetColorWhite(){
uint32_t strip_color = strip.Color(255, 255, 255);
for (int j=0; j<strip.numPixels(); j++) {
strip.setPixelColor(j, strip_color);
}
strip.show();
}
// this works!!
void fadeLoop(int satVal) {
int rbg_array[3];
unsigned long currentMillis = micros();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
H2R_HSBtoRGB(0, satVal, brightness, rbg_array);
uint32_t strip_color = strip.Color(rbg_array[0], rbg_array[1], rbg_array[2]);
for (int j=0; j<strip.numPixels(); j++) {
strip.setPixelColor(j, strip_color);
}
strip.show();
brightness += stepDirection;
if (brightness >= maxBrightness) {
stepDirection = -1;
interval = intervalDown;
}
if (brightness <= minBrightness) {
stepDirection = 1;
interval = intervalUp;
}
}
}
//void blinkRED() {
// simpleSetColorBlack();
// delay(blackTime);
// simpleSetColor(99);
// delay(redTime);
// simpleSetColorBlack();
// delay(blackTime);
// simpleSetColor(saturation);
//}
void printButtons() {
Serial.print("buttonOne: ");
Serial.println(buttonOne);
Serial.print("buttonTwo: ");
Serial.println(buttonTwo);
Serial.print("buttonThree: ");
Serial.println(buttonThree);
Serial.print("buttonFour: ");
Serial.println(buttonFour);
Serial.print("ledSpeed: ");
Serial.println(ledSpeed);
Serial.print("ledColorSaturation: ");
Serial.println(saturation);
}
void resetAllParams() {
ledSpeed = DEFAULT_LED_SPEED;
saturation = 0;
prevLedSaturation = 0;
}