Issue with serial monitor

Using an Arduino Uno / Latest version of IDE

I hit a bump in the road with my code so I threw one of my variables in the old serial monitor and all I get is random characters. Here is what I get every line it refreshes.


e !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮


Here is my code:
like I said it isn't working correctly right now, but I don't think that is the issue.
my baud rates match between serial and code and I've tried both 9600 and 4800 for good measure.
Any suggestions?

#include "FastLED.h"
#define NUM_LEDS 2
#define DATA_PIN 9
CRGB leds[NUM_LEDS];

int hue = 0;

/////////////// Switch 1

int S1 = digitalRead(7);
int S1Val = 0;
int DtVal = 0;

/////////////////////////////////

void setup() {
  Serial.begin(4800);

  pinMode(7, INPUT);
  pinMode(9, OUTPUT);

  FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);

  delay(500);
  START();
  delay(500);

}

void loop() {


  EVERY_N_MILLISECONDS(200) {
    DtVal = 0;
  }

  SWITCH1();

  ///////////////////////// BASIC COLORS (ON SWITCH 1)

    hue = S1Val;

    CHSV color = CHSV(hue, 255, 50);
    fill_solid(leds, NUM_LEDS, color);
    FastLED.show();
    
    Serial.write(S1Val); 

  ////////////////////////// switch reset

  SWITCH1RESET();

}

/////////////////////////// END OF LOOP

void START()
{
  fill_solid(leds, NUM_LEDS, CRGB(150, 0, 0));
  FastLED.show();
  delay(200);
  fill_solid(leds, NUM_LEDS, CRGB(0, 0, 0));
  FastLED.show();
  delay(200);
  fill_solid(leds, NUM_LEDS, CRGB(150, 0, 0));
  FastLED.show();
  delay(200);
  fill_solid(leds, NUM_LEDS, CRGB(0, 0, 0));
  FastLED.show();
}

//////////////////////////// VOIDS

void SWITCH1RESET()
{ if (S1Val > 255) {
    S1Val = 0;
  }
}

void OFF()
{ fill_solid(leds, NUM_LEDS, CRGB(0, 0, 0));
  FastLED.show();
}

void SWITCH1()
{
  if (S1 == 0) {
    S1Val++;
  }
  }

void DOUBLETAP()
{ DtVal = digitalRead(7);
  if (DtVal == 2) {
    S1Val = 0;
  }

}

You're using Serial.write which will send a byte value to the monitor. S1Val is cycling between 0 and 255 so the output you're getting ins exactly what you should be seeing. The first 128 are the ASCII symbol table, the final 128 are unprintable (unless you use extended codes or UTF). What is it that you expected to see on the monitor?

I was just going through the code again and saw that before I checked the forum. That was definitely a facepalm moment. Thank!

Any idea why my S1Val is incrementing without input from the button? I tried checking if it was equal to both 0 and 1 and it cycles either way without input.

Well, the dead give-away is that every pass through loop() you make a call to SWITCH1() and S1Val gets incremented. But, you say, only if SI == 0. You initiate S1 as digitalRead(7) (which at that stage of the proceedings means zero as pin 7 has yet to be defined), but never again do you read and update the value of S1.