Maker Pro
Maker Pro

Help Arduino Program

int pinA = 11;
int pinB = 12;
int val;

void setup()
{
pinMode(pinA, OUTPUT);
pinMode(pinB, INPUT);
}

void loop()
{
int();
}


void int()
{

val=digitalRead(pinB); // read data
if(pinB == HIGH)
{
Serial.println("PINA ON"); //write serially
}
else if(pinB == LOW)
{
Serial.println("PinA OFF"); //write serially
}
}

the message is keep repeating. how to stop the message in serial monitor even the pin is still in continuous active high or low status. it's just a one time message.
 
alright in that case you have many many options for this.

you can use your if statements with some small additions

Code:
int pinA = 11;
int pinB = 12;
int val;
int printed;

void setup()
{
pinMode(pinA, OUTPUT);
pinMode(pinB, INPUT);
printed = 0;
}

void loop()
{
int();
}

void int()
{
val=digitalRead(pinB); // read data
if([COLOR="Red"]val[/COLOR] == HIGH [COLOR="Blue"]&& printed == 0[/COLOR])
{
Serial.println("PINA ON"); //write serially
[COLOR="blue"]printed = 1;     //change state case to 1[/COLOR]
}
else if([COLOR="red"]val[/COLOR] == LOW [COLOR="blue"]&& printed == 1[/COLOR])
{
Serial.println("PinA OFF"); //write serially
[COLOR="blue"]printed = 0;     //change state case to 0[/COLOR]
}
}

first off you dont need to create a function for it, but I can understand your desire to do so.
second you weren't using "val" you were reading into it but not using it in the if statement so I fixed that. (red text)
Third... the big one, I added a state case (the variable "printed") to the if statement, so while it is high and the state is 0 it will print serially then change the state to 1 so it cannot meet the requirements of either the if or else, therefor not printing again. (blue text)

alternative ways you can do this are with case statements with a state variable, interrupts (though depending on the switch you may need to add some buffering in there), and any other way people can think of
 
hi sir/ma'am how to use eeprom i'm littlebit confused.

void setup()
{
for (int i = 0; i < 512; i++)
EEPROM.write(i, i);
}

that is the use of (i, i) can i use different characters like b,a?




#include "eeprom.h"


int pinA = 11;
int pinB = 12;
int val;
int printed;

void setup()
{
pinMode(pinA, OUTPUT);
pinMode(pinB, INPUT);
printed = 0;

}

void loop()
{
CheckPassword();

}

void CheckPassword()
{
checkNum=true;
lcd.print("Correct Password");
ChangePass();
int();
}
else
{
lcd.print("Incorrect Password");
}



void int()
{
val=digitalRead(pinB); // read data
if(val == HIGH && printed == 0)
{
lcd.printn("PINA ON");
printed = 1; //change state case to 1
}
else if(val == LOW && printed == 1)
{
lcd.print("PinA OFF");
printed = 0; //change state case to 0
}
}

void changePass();
{

(here to put eeprom codes)

}
 
Last edited:
Top