Show Posts
|
|
Pages: [1] 2
|
|
2
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: WHILE problem.. need help!
|
on: May 16, 2010, 02:58:35 pm
|
look people , i know my code is fine ! I need only the corect sintax ! look people , I can do : If (i==1) digitalWrite(ledPin, digitalRead(pPin)); if (i==0) digitalWrite(ledPin, LOW); but I need while (i==1) to do digitalWrite(ledPin, digitalRead(pPin)); and while (i==0) to do digitalWrite(ledPin, LOW); the value of i is changed before this stuff ! what is the right sintax ?
|
|
|
|
|
5
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: WHILE problem.. need help!
|
on: May 14, 2010, 06:40:09 am
|
Groove , Ok, I changed ... still not switching ! #include <ps2.h> PS2 kbd(3, 4); //3- clock; 4- DATA int pPin = 53; //sensor pin int ledPin = 13; void kbd_init() { char ack; kbd.write(0xff); ack = kbd.read(); ack = kbd.read();} //------------------------------------------------------ void setup() { kbd_init(); pinMode(pPin, INPUT); pinMode(ledPin, OUTPUT);} //------------------------------------------------------ void loop() {int i=2; unsigned char code; code = kbd.read(); //-------------------------------- if (code==0x69) {i=1;} if (code==0x72) {i=0;} //------------------------------------------------------
switch (i) { case 0: digitalWrite(ledPin, LOW); break; case 1: while (i!=0){ digitalWrite(ledPin, digitalRead(pPin));} //the problem is here ... a can not switch to 0 case, because in the bosy of while, the value of i is not refreshing ! is there something like echo in arduino language break;}
}
|
|
|
|
|
7
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: WHILE problem.. need help!
|
on: May 14, 2010, 06:32:32 am
|
The whole code : #include <ps2.h> PS2 kbd(3, 4); //3- clock; 4- DATA int pPin = 53; //sensor pin int ledPin = 13; void kbd_init() { char ack; kbd.write(0xff); ack = kbd.read(); ack = kbd.read();} //------------------------------------------------------ void setup() { kbd_init(); pinMode(pPin, INPUT); pinMode(ledPin, OUTPUT);} //------------------------------------------------------ void loop() {int i=2; unsigned char code; for (;;) { code = kbd.read(); //-------------------------------- if (code==0x69) {i=1;} if (code==0x72) {i=0;} //------------------------------------------------------
switch (i) { case 0: digitalWrite(ledPin, LOW); break; case 1: while (i!=0){ digitalWrite(ledPin, digitalRead(pPin));} //the problem is here ... a can not switch to 0 case, because in the bosy of while, the value of i is not refreshing ! is there something like echo in arduino language break;
}}
|
|
|
|
|
9
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: WHILE problem.. need help!
|
on: May 13, 2010, 03:32:46 pm
|
|
OK pPin is a DSC pir sensor ... when is no movement its LOW when is movement its HIGH
i==1 is ARMED state ... when the pPin is HIGH , it lighs the led when pPin is LOW, the led is turned off...
i==0 is NORMAL status ... whatever pPin state is , the led is turned off
|
|
|
|
|
11
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: WHILE problem.. need help!
|
on: May 13, 2010, 09:55:05 am
|
|
I connected the ps2Keyboard to the board for ex. i=1 is when I press button "alt" and i=0 when I press "ctrl" ! i changes the value before the while stuff ...the while's are at the and of the code ...
the body are not the same...
in i==1
if (digitalRead(pPin) == HIGH) digitalWrite(ledPin,HIGH ); if (digitalRead(pPin) == LOW) digitalWrite(ledPin,LOW);}
and in i==0 I have
if (digitalRead(pPin) == HIGH) digitalWrite(ledPin,LOW ); if (digitalRead(pPin) == LOW) digitalWrite(ledPin,LOW);}
|
|
|
|
|
12
|
Forum 2005-2010 (read only) / Syntax & Programs / WHILE problem.. need help!
|
on: May 13, 2010, 08:01:38 am
|
So , I have an "i" variable , that has to lets say states: s=0 and s=1... When (i==1) I need to do if (digitalRead(pPin) == HIGH) digitalWrite(ledPin,HIGH ); if (digitalRead(pPin) == LOW) digitalWrite(ledPin,LOW); and when (i==0) to do if (digitalRead(pPin) == HIGH) digitalWrite(ledPin,LOW ); if (digitalRead(pPin) == LOW) digitalWrite(ledPin,LOW); When Im doing this with WHILE it works only in a half.. the second part with (i==0) is ignored ! while(i==1) { if (digitalRead(pPin) == HIGH) digitalWrite(ledPin,HIGH ); if (digitalRead(pPin) == LOW) digitalWrite(ledPin,LOW);}
while(i==0) { if (digitalRead(pPin) == HIGH) digitalWrite(ledPin,LOW ); if (digitalRead(pPin) == LOW) digitalWrite(ledPin,LOW);}
|
|
|
|
|
13
|
Forum 2005-2010 (read only) / Syntax & Programs / PS/2KEYBOARD Password check
|
on: May 07, 2010, 01:44:50 pm
|
Hello! I want to light the led when the password entered from the keyboard is the same as programm for leds ON and other password for led OFF. I use only the numpad.. so there is only numbers ... and I would like to make a delay after 3 incorect passwords entered... something like : passON=12345+; ( the + is the button '+' 0x79) passOFF=12345enter ( the enter is the button 'Enter' 0xE0 0x5A ) if am right if (passON== inpass) digitalWrite(ledPin, HIGH); if (passOFF== inpass) digitalWrite(ledPin, LOW); I'll use thes code ... I'm new in arduino, so i'll be happy if someone will help me... #include <ps2.h>
PS2 kbd(3, 4);
void kbd_init() { char ack; kbd.write(0xff); // send reset code ack = kbd.read(); // byte, kbd does self test ack = kbd.read(); // another ack when self test is done }
void setup() { Serial.begin(9600); kbd_init(); } void loop() {int m; unsigned char code; for (;;) { /* ever */ /* read a keycode */ code = kbd.read(); } }
|
|
|
|
|
15
|
Forum 2005-2010 (read only) / Troubleshooting / Re: Interfacing with Parallax RFID Reader/Writer
|
on: November 04, 2010, 04:46:37 am
|
progress ! the led turned in to red ... thanks ! mySerial.print(RFID_READ, BYTE); its right ! When the module is successfully powered-up and is in an idle state, the LED will be GREEN; when the module is in an active state (for example, searching for a valid tag or performing an operation on the tag), the LED will be RED.
|
|
|
|
|