Passing value via Serial Monitor to change neopixel

Working on building out a project to pass a single digit via RF to two arduino nanos that will change the color of small neopixel strips connected to them. For now, I just wanted to test sending a value to change the color of the strip by sending a value via the serial monitor but I have got something backwards at the moment.

#include <Adafruit_MPR121.h>
#include <CapacitiveSensor.h>
#include <Adafruit_NeoPixel.h>
#define PIN            10

// How many NeoPixels are attached to the Arduino?
int numPixel = 4;
//length of delay
int r = 5000;
char receivedChar;
boolean newData = false;

Adafruit_NeoPixel strip(numPixel, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 5000; // delay for half a second

void setup() {

  Serial.begin(9600);
  Serial.println("Enter test color");

  strip.begin(); // This initializes the NeoPixel library.
  strip.setBrightness(60);
  strip.show();
  
}

void loop()
{
  
    recvOneChar();
    showNewData();
    
}

void recvOneChar() {
    if (Serial.available() > 0) {
        receivedChar = Serial.read();
        newData = true;
    }
}

void showNewData() {
    uint32_t a = strip.Color(1, 20, 255);
    uint32_t b = strip.Color(11, 255, 1);
    uint32_t c = strip.Color(255, 1, 1);
    if (newData == true) {
      strip.fill(receivedChar, 0, numPixel);
      strip.show();
      //Serial.print("This just in ... ");
      Serial.println(receivedChar);
      newData = false;
    }
}

I have tried moving the uint32 to Setup() but its still no good. Only thing I can think of is that the Serial monitor is not getting strictly the single character I am sending it but I only guessing that based on changing the Serial monitor to No Line Ending. Doing so causes the brightness of the lights to match the setting I set for the brightness setting earlier in the code. Otherwise, any value that I input to the Serial Monitor turns the lights blue but very dimly.

What do you really send through Serial? You only read one byte...

See Serial Input Basics

I'm only using the serial input to test that my other code is working. It's temporary until I get the RF receivers wired up. I did use the serial basics link that you supplied when I was learning to do this but I am still not sure what I am overlooking or what I did wrong here.

you only receive one byte which is ok if you removed indeed CR/LF from the console but you still receive ASCII (for example if you type the character 1 you read 49 in your code as this is the ascii code for ‘1’ - you handle it without any test on what it is and not sure what you do with a b c

I am used to visual basic coding so I think I am struggling with this part being completely different. Just to make sure I am following, You are saying I need to declare a b and c as character variables so that the console will see them as actual letters and not their ASCII codes?

No I’m saying a,b and c are unused in your code, so useless

Aha! That's my disconnect then... I am trying to send A, B or C through the serial monitor into the receivedChar variable thinking that since assigned A, B and C as the color codes prior it would work. Do I just need to use an If statement to assign the colors instead?

Allordacia1:
Aha! That's my disconnect then... I am trying to send A, B or C through the serial monitor into the receivedChar variable thinking that since assigned A, B and C as the color codes prior it would work. Do I just need to use an If statement to assign the colors instead?

Sorry I totally don’t get your idea...

uint32_t a = strip.Color(1, 20, 255);
uint32_t b = strip.Color(11, 255, 1);
uint32_t c = strip.Color(255, 1, 1);

have you checked what the color method does?

a,b and c are defined as 3 color variables described with well defined R,G and B components. How the heck would they be connected to whatever you type in the serial console?

J-M-L:
Sorry I totally don’t get your idea...

I might not either... I am looking at it as "a = strip.color(1, 20, 255)" so that when the serial console later receives 'a' it will plug that color into the "strip.fill(receivedChar, 0, numPixel)" the "uint32_t a = strip.Color(1, 20, 255);" works fine if i set up the code to run straight through and display a color so I was trying to preserve resources by switching them with a variable.

Well not being judgmental here as we all started somewhere but really my best advice is that you need to put your project aside and read a C programming tutorial. Once you understand variables and general constructs, then you can come back to your project...

No judgement taken at all, I appreciate your help. C is very different than the coding that I do for my day job so I have to learn to think about this differently. Not ready to quit, I will keep experimenting and researching the answer.

Basically you want your loop to do:

If I have received an entry then
  If this entry is ‘a’ then {do this}
  Else 
  If this entry is ‘b’ then {do that}
  Else
  If this entry is ‘c’ then {do something else}
  Else ignore this entry (ie do nothing)

Look at switch/case or if/else constructs

This is exactly what I am experimenting with right now using case. The previous endeavor was to try and keep my code lean but as you mentioned I need to do a lot more diving into how assigning variables work with C. Thank you for all of your help!

you can keep the code lean but black magic and hope rarely work :slight_smile:

J-M-L:
you can keep the code lean but black magic and hope rarely work :slight_smile:

Dont kill my hopes and dreams of one day being wizard!

BTW, switch/case worked perfectly... going to roll with it! Thanks!

I said "rarely" --- who knows :smiley: :smiling_imp: