-Solved- Serial.println not working?

Hello everyone.

I am trying to print data to the Serial Monitor, but to no avail. The TX and RX flash when I upload the sketch, but don’t do anything afterwards.

I’m using Windows 8.1, an Arduino Uno, and version 1.8.5. of the Arduino IDE.

From what I remember, I have done the following:

Turned the computer off and on again.

Made sure the baud rates in both the code and the Serial Monitor are the same.

Connected to the correct port.

Here’s my code:

byte vision = 3;

void setup() {

  pinMode(vision, INPUT);

  Serial.begin(9600);
}

void loop() {

  byte spikeTime = millis();
  byte spikeSum = 0;

  byte inp1 = analogRead(vision);

  byte layer1 = 1;

  byte synapse1 = 1;

  while (spikeTime < 1000) {

    if (inp1 > 0) {

      spikeSum += 1 * bitRead(inp1, 0);
    }
  }

  delay(1000);
  
  Serial.println(spikeSum);

  Serial.flush();
}

Long story short: how can I get the Serial Monitor working again? What am I doing to make the Serial Monitor not show anything?

I would greatly appreciate any help you can give me. Thank you.

Do the Examples --> Basics --> ReadAnalogVoltage

It never gets last the while loop, because you never update spiketime1 in the loop... (not clear to me what you intend to happen there)

Thank you very much for your quick replies!

@ieee488: I ran the example, which oddly worked. But when I ran my code again, even when I modified it to be like the example, it stopped working again.

@DrAzzy: Thank you for catching the while loop problem! The while loop was meant to run for as long as millis() (in the form of spikeTime) is less than one second.

I’m trying to imitate a paper where they successfully put a spiking neural network that used only bits and simple logic into a robot’s microcontroller.

But the Serial Monitor still won’t work with my code... perhaps it does have to do with the code?

Edit: Aha! It was in the code! I uncommented the while loop and the Serial Monitor worked just fine. Now to possibly find a different way to count seconds. Thank you so much for your help, guys!

The easy way to count seconds is to just use the millis function which is already counting milliseconds and divide by 1000.

If you need to time an interval then take a reading from millis at the beginning and end and subtract to see how long it has been.

Thank you very much for the tip. I will definitely keep it in mind!

This topic has been resolved. Thank you all so much again!