// TEST: can a bug in the code issue a change in the simulation beviour ?
//
// Trying to write faulty code that makes a difference
// between a button click with the mouse or with the keyboard.
//
// Conclusion: No, that is not possible for an Arduino Uno
unsigned long counter = 0;
int oldValue = HIGH;
char buffer_before[8];
char buffer[8];
char buffer_after[8];
void setup()
{
Serial.begin(115200);
pinMode(2,INPUT_PULLUP);
// fill the buffers
memset(buffer,'X',8);
memset(buffer_before,'#',8);
memset(buffer_after,'*',8);
}
void loop()
{
int value = digitalRead(2);
if(value != oldValue)
{
counter++;
ultoa(counter,buffer-2,10); // BUG
// Remove the zero terminator
int n = strlen(buffer);
buffer[n] = '='; // BUG
Serial.print(buffer);
Serial.print(buffer_before);
Serial.println(buffer_after);
oldValue = value;
}
}