Basic Serial Monitor Question

I'm new. Can somebody point me in the right direction. please.

Question: Is there a way to print to the serial monitor only when the status of an input has changed. Currently my code is indicating its status to the monitor each time it goes through the loop. I am trying to clean that up.

Thank you,
TacomaSparky

boolean PreviousValue;

void loop( void )
{
  boolean ThisValue;

  ThisValue = digitalRead( 7 );

  if ( ThisValue != PreviousValue )
  {
    // Your print goes here.
    PreviousValue = ThisValue;
  }
}

Can somebody point me in the right direction. please.

Only if you post your sketch so we can see how you are trying to do it now.

Lefty

I am trying to figure out where to start. Here is my code as of now. I am attempting to keep the "standby" (located at the beginning of the Loop) from constantly appearing on the monitor. Currently looking into this "boolean" Data Type to see if I can understand how to integrate it. This is my first project I am using to teach myself how Arduino works. It is a single axis joystick previously equipped on a Scissor-type man lift. Joystick controller operates using a center-tapped pot with some contacts underneath the "swing" of the joystick to distinguish between forward and reverse.

int potentiometerPin = 0; //analog pin controlled by joystick
int valpot = 0; //pot value for determining forwardLED brightness
int triggerVal = 0; //triggerVal used to store the state of trigger
int FWDVal = 0;
int RVRSVal = 0;
int leftBlinkVal = 0; // val will be used to store the state of the input pin
int old_leftBlinkVal = 0; // this variable stores the previous value of "val"
int leftState = 0; // 0 = leftblink off and 1 = leftblink on

int rightBlinkVal = 0; // val will be used to store the state of the input pin
int old_rightBlinkVal = 0; // this variable stores the previous value of "val"
int rightState = 0; // 0 = rightblink off and 1 = rightblink on

#define forwardLED 11 //brightness simulates forward speed
#define reverseLED 10 //brightness simulates reverse speed
#define standbyLED 9 //not forward or reverse
#define joystickFWDcontact 8 //rolling contact under joystick
#define joystickRVRScontact 7 //rolling contact under joystick
#define buzzer 6 //the pin for the buzzer controlled by trigger
#define leftLED 5 //pin left blinker is connected to
#define rightLED 4 //pin right blinker is connected to
#define trigger 3 //pin trigger is connected to
#define leftButton 2 //pin leftButton is connected to
#define rightButton 12 //pin rightButton is connected to

void setup ()
{
Serial.begin (9600);
pinMode (forwardLED, OUTPUT);
pinMode (reverseLED, OUTPUT);
pinMode (standbyLED, OUTPUT);
pinMode (buzzer, OUTPUT);
pinMode (leftLED, OUTPUT);
pinMode (rightLED, OUTPUT);

pinMode (joystickFWDcontact, INPUT);
pinMode (joystickRVRScontact, INPUT);
pinMode (trigger, INPUT);
pinMode (leftButton, INPUT);
pinMode (rightButton, INPUT);

}

void loop(){
valpot = analogRead (potentiometerPin); //joystick pot value
FWDVal = digitalRead (joystickFWDcontact);
RVRSVal = digitalRead (joystickRVRScontact);
if
((FWDVal == LOW) &&
(RVRSVal == LOW)){
digitalWrite (standbyLED, HIGH);
Serial.print ("Standby");
Serial.println (); //added to print vertically on Monitor.
analogWrite (reverseLED, 0); //erases any stored value kept from "valpot"
analogWrite (forwardLED, 0); //erases any stored value kept from "valpot"
delay (100);
}else{
digitalWrite (standbyLED, LOW);

}
if
((FWDVal == HIGH) &&
(RVRSVal == LOW)){
analogWrite (forwardLED, valpot/4); //divided by 4 because of the differences between
// "analogRead"(0 -1023)and "analogWrite" (0-255)
//Boo-yah!
Serial.print ("Forward Speed = ");
Serial.println (valpot);
//delay (10); //just hang on 1/100th a sec.
}

if
((FWDVal == LOW) &&
(RVRSVal ==HIGH)){
analogWrite (reverseLED, valpot/4);
Serial.print ("Reverse Speed = ");
Serial.println (valpot);
//delay (10); //just hang on 1/100th a sec.
}

//just the code for the trigger
triggerVal = digitalRead (trigger); //defines trigger being squeezed
if (triggerVal == HIGH) { //is trigger pushed or not
digitalWrite (buzzer, HIGH); //if it is, turn on the damn buzzer!
}else{ //otherwise. . .
digitalWrite (buzzer, LOW); //the opposite of "on" numbnuts.
//it stays off.
}
{
leftBlinkVal = digitalRead(leftButton); // read input value and store it
// dead sexy

// check if there was a transition
if ((leftBlinkVal == HIGH) && (old_leftBlinkVal == LOW)){
leftState = 1 - leftState;
delay(10); //just chill yo
}

old_leftBlinkVal = leftBlinkVal; // val is now old, let's store it

if (leftState == 1) {
digitalWrite(leftLED, HIGH); // turn LED ON
} else { //otherwise. . .
digitalWrite(leftLED, LOW); //off sucka!
}
}
{
rightBlinkVal = digitalRead(rightButton); // read input value and store it
// dead sexy

// check if there was a transition
if ((rightBlinkVal == HIGH) && (old_rightBlinkVal == LOW)){
rightState = 1 - rightState;
delay(10); //just chill yo
}

old_rightBlinkVal = rightBlinkVal; // val is now old, let's store it

if (rightState == 1) {
digitalWrite(rightLED, HIGH); // turn LED ON
} else { //otherwise. . .
digitalWrite(rightLED, LOW); //off sucka!
}
}
}

The first reply post answered this flawlessly...