Have a bit of code here that outputs a square wave. Swaps a variable from 0 to 1 over and over. I turn on the serial plotter and I see a square wave just as I expect.
In my loop() I look for incoming bytes from the serial port so I can use the information to change pulse widths. But, No incoming bytes are ever "seen" by my code while the serial plotter window is active.
I can switch off the serial plotter window and turn on the serial monitor window and the I can enter numbers to switch the pulse width, everything is fine.
What I'm I doing wrong such that the inputting of bytes from the serial plotter won't work?
The code..
#include "squareWave.h"
#include "timeObj.h"
int signal;
class testWave : public squareWave {
public:
virtual void pulseOn(void);
virtual void pulseOff(void);
};
void testWave::pulseOn(void) { signal = 1; }
void testWave::pulseOff(void) { signal = 0; }
testWave ourSquareWave;
char inBuff[100];
int i;
timeObj outTimer(10);
void setup() {
signal = 0;
i =0;
ourSquareWave.setPeriod(1000);
ourSquareWave.setPulse(250);
ourSquareWave.setOnOff(true);
outTimer.start();
}
void loop() {
char aChar;
int newVal;
idle();
if (Serial.available()) {
aChar = Serial.read();
if (aChar=='\n') {
inBuff[i] = '\0';
i = 0;
newVal = atoi(inBuff);
ourSquareWave.setPulse(newVal);
Serial.print("Set pulse to : ");
Serial.println(newVal);
} else {
inBuff[i++] = aChar;
}
}
if (outTimer.ding()) {
Serial.println(signal);
outTimer.start();
}
}
Thanks!
-jim lee