I was testing my RGB (common anode) on its own playing with colours and got the red, green to work as desired.
However, when I connected my LCD board to my Arduino Uno as well as the RGB (using the same code prior and same output pins so I know the code isn't the issue) the RGB no longer displays red.
I assume it has something to do with the fluctuating voltage/current after I've put in the LCD but I cant work out how to resolve it. When its meant to be red it's just nothing, doesn't light up, green however still works.
#include <LiquidCrystal.h>
#define COMMON_ANODE
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int SelectCounter = 0;
int hours = 0; // start hours
int minutes = 0; //start min
int seconds = 5; //start seconds
int redPin = A1;
int greenPin = 2;
int bluePin = 3;
int digitposition = 0;
int readkey;
int speaker = A5;
int buttonPin = A4;
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0;
void setup() {
pinMode(speaker, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
void loop() {
noTone(speaker);
setColor(0, 0, 255); // red
....... }
void trigger() {
lcd.clear(); // clears the screen and buffer
lcd.setCursor(6,0);
lcd.println("MUM: ");
lcd.setCursor(4, 1); // set timer position on lcd for end.
lcd.println("WAKE UP! ");
tone(speaker, 10);
setColor(0, 255, 0); // green
delay(500);
digitalWrite(A1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
noTone(speaker);
delay(500);
lcd.display();
}
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
analogWriteworks on PWM pins only.