pradeep_k_b
Full Member level 3
- Joined
- Dec 21, 2011
- Messages
- 160
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,306
- Location
- Nilambur, India
- Activity points
- 2,509
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("1"); //turn on the LED
delay(1000);
Serial.println("0");//turn off the LED
delay(1000);
}
int ledPin = 13; // use the built in LED on pin 13 of the Uno
int state = 0;
int flag = 0; // make sure that you return the state only once
void setup() {
// sets the pins as outputs:
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600); // Default connection rate for my BT module
}
void loop() {
//if some data is sent, read it and save it in the state variable
if(Serial.available() > 0){
state = Serial.read();
flag=0;
}
// if the state is 0 the led will turn off
if (state == '0') {
digitalWrite(ledPin, LOW);
if(flag == 0){
Serial.println("LED: off");
flag = 1;
}
}
// if the state is 1 the led will turn on
else if (state == '1') {
digitalWrite(ledPin, HIGH);
if(flag == 0){
Serial.println("LED: on");
flag = 1;
}
}
}
int ledPin = 13; // use the built in LED on pin 13 of the Uno
char state = 0;
bit received = 0;
void setup() {
// sets the pins as outputs:
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600); // Default connection rate for my BT module
}
void loop() {
if(received) {
// if the state is 0 the led will turn off
if(state == '0') {
digitalWrite(ledPin, LOW);
Serial.println("LED: off");
}
// if the state is 1 the led will turn on
else if(state == '1') {
digitalWrite(ledPin, HIGH);
Serial.println("LED: on");
}
received = 0;
}
}
void serialEvent() {
while (Serial.available()) {
// get the new byte:
state = (char)Serial.read();
received = 1;
}
}
void loop()
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?