Issues with LCD and my code

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Joe36
 
Posts: 44
Joined: Tue Dec 27, 2016 10:36 am

Issues with LCD and my code

Post by Joe36 »

Hello,
I have created a project box that allows the testing of Neopixels as we use them for many displays, sometimes people want to see a range of colors then pick one so I created a box with some POT's and a display so you can see the 0-255 values when a color is picked. To make this project work with RGB & RGBW I added some code that allows the press of a button to switch between each. What's confusing me is I want to align the text and value outputs on my LCD but when I add spaces to do this I somehow break the RGBW function, I cannot figure this out. Specifically if I place blank spaces after RED in this line lcd.print("RED "); that's when it stops working, but only 3 or more spaces. 2 spaces it works fine. anyone have any ideas? full code attached Thanks

Code: Select all

#include <Arduino.h>  
#include <Adafruit_NeoPixel.h>
#include <LiquidCrystal.h> 
#include <ResponsiveAnalogRead.h>
#include <Wire.h>
#include <EEPROM.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd (12, 11, 7, 6, 5, 4);

Adafruit_NeoPixel stripRGB =  Adafruit_NeoPixel(200, 3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripRGBW = Adafruit_NeoPixel(200, 3, NEO_GRBW + NEO_KHZ800);

// Button & debounce 
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
const int buttonPin = 10;  // Pin used to toggle modes
int buttonState;
int lastButtonState = HIGH;
bool mode   =  0;  // 0=RGB, 1=RGBW
bool modeChanged = false;

//Pot inputs
const int potPinR = A0;
const int potPinG = A1;
const int potPinB = A2;
const int potPinW = A3;
//Smoothing setup
ResponsiveAnalogRead inputR(potPinR, true, 0.1);
ResponsiveAnalogRead inputG(potPinG, true, 0.1);
ResponsiveAnalogRead inputB(potPinB, true, 0.1);
ResponsiveAnalogRead inputW(potPinW, true, 0.1);

int readingR = 0;
int readingG = 0;
int readingB = 0;
int readingW = 0;
int alphaR = 0;
int alphaG = 0;
int alphaB = 0;    
int alphaW = 0;

// *******************************************************************************************************   
void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  mode = !EEPROM.read(0);
  Serial.println(mode);
  lcd.begin(20, 4, 2);
  Serial.begin(9600);
}

// *********************************************************************************************************

void loop() {
  
  // RGB/RGBW button and debounce
  int reading  = digitalRead(buttonPin);
  // If the switch changed, due to noise or pressing:
  if (reading != lastButtonState) lastDebounceTime = millis();
  if ((millis() - lastDebounceTime) > debounceDelay) {
    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;
      // only toggle the Mode if the new button state is HIGH
      if (buttonState == HIGH) {
        mode = !mode;
        EEPROM.write(0, mode);
        modeChanged = true;
      }
    }
  }  
  lastButtonState = reading; // save the reading


  //update smoothed analog values
  inputB.update();
  inputR.update();
  inputG.update();
  inputW.update();

  readingR  = inputR.getValue();
  alphaR = map(readingR, 0, 1023, 0, 255);
  
  readingG  = inputG.getValue();
  alphaG = map(readingG, 0, 1023, 0, 255);
  
  readingB  = inputB.getValue();
  alphaB = map(readingB, 0, 1023, 0, 255);  
  
  readingW  = inputW.getValue();
  alphaW = map(readingW, 0, 1023, 0, 255);
  

  lcd.setCursor(0, 0);
  lcd.print("RED ");
  lcd.print(alphaR);
  lcd.print("   ");
  lcd.setCursor(0, 1);
  lcd.print("GREEN ");
  lcd.print(alphaG);
  lcd.print("   ");
  lcd.setCursor(0, 2);
  lcd.print("BLUE ");
  lcd.print(alphaB);
  lcd.print("   ");

  // RGB
  if (mode ==0){  
    if (modeChanged == true) stripRGB.begin();
    for (uint16_t i = 0; i < stripRGB.numPixels(); i++) {
      stripRGB.setPixelColor(i, alphaR, alphaG, alphaB, alphaW);
    }
    stripRGB.show();
    modeChanged = false;
    lcd.setCursor(0, 3);
    lcd.print("          ");
   // delay(25);
  }

  // RGBW
  if (mode ==1){
    if (modeChanged == true) stripRGBW.begin();      
    for (uint16_t i = 0; i < stripRGBW.numPixels(); i++) {
      stripRGBW.setPixelColor(i, alphaR, alphaG, alphaB, alphaW);
    }
    stripRGBW.show();
    modeChanged = false;
    lcd.setCursor(0, 3);
    lcd.print("WHITE ");
    lcd.print(alphaW);
    lcd.print("   ");
   // delay(25);
  }

  }
  

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”