I am having a problem printing out an array which was loaded with AAA, ie 65 65 65, at run time and then I change it to BBB, ie 66, 66, 66, after a pushbutton is pressed.
It keeps printing out the 65, 65, 65 and ignoring what I have changed it to.
Is this a global issue?
uint8_t buff[] = "AAA"; //load buffer with AAA
const int buttonPin1 = 0; //the number of the pushbutton pin
int buttonState1 = 0; //variable for reading the pushbutton status
void setup()
{
pinMode(buttonPin1, INPUT_PULLUP);//initialize the pushbutton pin as an input
}
void loop()
{
buttonState1 = digitalRead(buttonPin1); // check if the pushbutton is pressed. If it is, the buttonState is LOW:
delay(200); //slow down to avoid repeated button reads
if (buttonState1 == LOW) {
Serial.println("button1 pressed"); //acknowledge button pressed
uint8_t buff[] = "BBB"; //change the buffer to BBB
myPnt(); //send to serial print
}
}
void myPnt()
{
for (int x = 0; x < 3; x++)
{
Serial.println(buff[x]); //out to serial print
}
}
Usually chars are stored in a char buffer[].
So change uint8_t to char.
Or maye change uint8_t to int8_t.
Or cast your character to a uint8_t inside the for loop. (uint8_t) 'b'