#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#include <EEPROM.h>
int ledFeedbackAmount = 5; // Amount of feedback LEDS
// Leds (LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800)
Adafruit_NeoPixel ledStripLeft (1, 4, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ledStripMid (1, 3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ledStripRight (1, 5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ledStripFeedback (ledFeedbackAmount, 7, NEO_GRB + NEO_KHZ800);
// Halls
int hallLeft = A2;
int hallMid = A0;
int hallRight = A1;
// Colors
uint32_t white = ledStripFeedback.Color(255, 255, 255);
uint32_t yellow = ledStripFeedback.Color(255, 255, 0);
uint32_t orange = ledStripFeedback.Color(255, 60, 0);
uint32_t red = ledStripFeedback.Color(255, 0, 0);
uint32_t pink = ledStripFeedback.Color(255, 0, 60);
uint32_t lightblue = ledStripFeedback.Color(0, 125, 255);
uint32_t green = ledStripFeedback.Color(0, 255, 0);
uint32_t blue = ledStripFeedback.Color(0, 0, 255);
uint32_t magenta = ledStripFeedback.Color(255, 0, 255);
uint32_t ledOff = ledStripFeedback.Color(0, 0, 0);
//Module moduleName(Adafruit_NeoPixel led, uint32_t color, unsigned long timeLedNeedsToStayOn, boolean ledState, int hallBaseValue) {
//States
bool stateLeft = 0;
void setup()
{
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
Serial.begin(9600);
pinMode(hallLeft, INPUT);
pinMode(hallMid, INPUT);
pinMode(hallRight, INPUT);
ledStripLeft.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
ledStripMid.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
ledStripRight.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
ledStripFeedback.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}
void loop(){
ledStripLeft.setPixelColor(0, green);
ledStripLeft.show();
delay(2000);
Module moduleLeft(ledStripLeft, red, 2000, 1, analogRead(hallLeft));
moduleLeft.check();
delay(500);
moduleLeft.LedOff();
delay(300);
}
/*
* MODULE CLASS DECLARATION
*/
#include <Adafruit_NeoPixel.h>
class Module {
private:
Adafruit_NeoPixel led;
boolean ledState;
unsigned long timeLedNeedsToStayOn;
uint32_t color;
int hallBaseValue;
public:
Module(Adafruit_NeoPixel led, uint32_t color, unsigned long timeLedNeedsToStayOn, boolean ledState, int hallBaseValue) {
SetLed(led);
SetColor(color);
SetTimeLedOn(timeLedNeedsToStayOn);
SetLedState(ledState);
SetHallBaseValue(hallBaseValue);
}
//------------ Setters ----------------
void SetLed(Adafruit_NeoPixel l) {
led = l;
}
void SetColor(uint32_t c) {
color = c;
}
void SetTimeLedOn(long t) {
timeLedNeedsToStayOn = t;
}
void SetLedState(bool ls) {
ledState = ls;
}
void SetHallBaseValue(int h) {
hallBaseValue = h;
}
//------------ Getters ----------------
void GetLed() {
return led;
}
uint32_t GetColor() {
return color;
}
void GetTimeLedOn() {
return timeLedNeedsToStayOn;
}
void GetLedState() {
return ledState;
}
void GetHallBaseValue() {
return hallBaseValue;
}
//------------ Setters ----------------
// Checks whether it is time to turn on or off the LED.
void check() {
Serial.println(color);
led.setPixelColor(0, color);
led.show();
}
void LedOff() {
led.setPixelColor(0, 0, 0, 0);
led.show();
}
};
So Im cracking my head over this problem for the last couple of days. My led turns green without a problem. It even prints the color inside my class.check() but it just simply wont change to the color red. what am i doing wrong?