For me, it was displaying the first point where i = 0, sin = 0, cos = 220.
Is the problem that the code has started running before the Serial Plotter has opened fully?
Or is it because the screen keeps scrolling and you can't stop it at the right time?
Here is some modified code that waits for a push button (connected between buttonPin and GND) to be pressed before starting to plot.
I've used a for loop so that it only plots a single cycle from 0° to 360°.
Pressing the button again will plot another cycle.
int i = 0;
float ySin;
float yCos;
int buttonPin = 2;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
delay(200);
}
void loop() {
while (digitalRead(buttonPin)) {
// do nothing until button is pressed
}
for (int i = 0; i <= 360; i++) {
Serial.print("_:-250 __:250 "); // Prevent change to Y axis scale by plotter's auto-scaling feature.
ySin = 220 * sin((PI / 180.0) * i);
yCos = 220 * cos((PI / 180.0) * i);
Serial.print("Sin:");
Serial.print(ySin);
Serial.print(" ");
Serial.print("Cos:");
Serial.println(yCos);
delay(1);
}
}
I've got the number of points plotted set to 500, but it still stops after plotting to 360° the first time around.