I have my RGB LCD pins connected to 45, 44, 46, respectively, and I am able to see output only when I output the blue pin. I have a function colorPicker(int r, int g, int b) that takes in 3 integer values between 0-255. It outputs the subsequent analog value. If I have colorPicker(255, 0, 0) to test red, or colorPicker(0, 255, 0) to test green, I get a blank screen on my LCD screen. But if I do colorPicker(0, 0, 255) to test blue, I get my blue color.
Now before you tell me to check my wires and connections and all that 'necessary-prevention-method-for-a-timely-solution' business, when I have colorPicker(0, 255, 255), I actually get purple! When I try any combination, always including some value for the blue, I get different colored outputs. Only when blue isn't triggered do I get a blank screen.
Code is in check (let me know if you need to look at it).
Wiring is in check (hopefully, in my inexperienced world I still easily could have missed something).
Any thoughts on this puzzle?
Actually, here's the code anyway...
#include <LiquidCrystal.h>
#include <SPI.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const int red = 45;
const int green = 44;
const int blue = 46;
volatile boolean process_it;
char buff[2];
volatile byte spot = 0;
void setup()
{
Serial.begin(115200);
lcd.begin(16,2);
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
SPCR |= bit(SPE);
SPI.attachInterrupt();
}
ISR (SPI_STC_vect)
{
byte b = SPDR;
buff[spot] = b;
spot++;
if (spot > 1) {
spot = 0;
process_it = true;
}
}
void loop() {
if (process_it)
{
byte c = buff[0];
byte s = buff[1];
Serial.println(c);
situation(s);
background(c);
process_it = false;
}
delay(300);
}
void background(byte color) {
switch (color)
{
case 0:
colorPicker(255,0,0);
break;
case 1:
colorPicker(0,255,0);
break;
case 2:
colorPicker(0,0,255);
break;
case 3:
colorPicker(127,0,255);
break;
case 4:
colorPicker(255,51,153);
break;
case 5:
colorPicker(0,255,255);
break;
case 6:
colorPicker(255,255,0);
break;
case 7:
colorPicker(255,128,0);
break;
case 8:
colorPicker(224,224,224);
break;
case 9:
colorPicker(153,153,0);
break;
}
}
void colorPicker(int r, int g, int b) {
analogWrite(red,r);
analogWrite(green,g);
analogWrite(blue,b);
}
So every case you see that has a 0 in the blue spot does not produce a color, but the rest do.
- I am running SPI information from an FPGA in Labview. All relatively unimportant, my oscilloscope shows the data line coming in is ok. When I print the byte value of 'c', I get what I selected in my FPGA interface.
- Ignore the ISR function, I am also incorporating a string display system based on the same idea as the color display system. Each is represented by a byte, I send over 16 bits for 2 bytes, and the buffer stores those byte values and displays them to my serial monitor.
Again, everything works accordingly (as far as I know).