Could you please help me out with the fallowing code .
The main idea is that i want the loop to keep moving until i send a new input from my keyboard
The code bellow works but after 1 iteration , c loses it's value and when i print it i does not return any value .
Hope you can help . :o
Thank you!
AWOL:
Are you using the serial monitor?
(I'm sorry I can't post all of my answer)
yes .
if i define global variable c ='h' it will hod value in all stages of the program
but if i input from keyboard lets say 'h' the value will not be retained in c and will not go in that IF for the second time .
In a later stage i will have an App on my Android phone ( receive data from different senors and control parts of a system.
you sir are not helping .
i'm not trying to get something that is already done , i'm stuck at this point and don't have a clue to work around it.
if it make you any happier i will explain , if i post all the code here , and by a change they find it , it will be considered that i got it from here ( even tho i'm the source ) and dismiss my paper
Robin2:
So you just want us to help you cheat in a way that won't get you caught ?
Ares111111111:
if i post all the code here , and by a change they find it , it will be considered that i got it from here ( even tho i'm the source ) and dismiss my paper
That would make the people responsible for such decisions unreasonable and incompetent. That seems unlikely.
Was "no outside help" included in your assignment?
you can get all the help in the world ... but they check your paper with a computer program ... and if that program finds your paper like ... let's say 60 % similar to other projects ... then that is considered cheating ..
by posting all of my code here i open up to that and after all my work i'm not happy or willing to do it .
now that you know it all ... could someone shine a lite upon my "little" problem ... please ?????
i turn to this forum as a last resort ( i spend half a day writing different codes to make it work with no luck )
What have you got the line ending set to in the Serial monitor ?
Consider what will happen in your program if more than one character is in the input buffer
I made a few changes: I substituted the built in LED for the motor, and I have it print the value of c. it toggles the LED - we don't all have a servo laying about. a = on, b = off. it runs continuously. I wonder if you are hitting enter after you type a or b?
int LED = 13 ;//
char c;
char x;
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
}
void loop ()
{
if (Serial.available() != 0)
{
x = Serial.read();
c = x ;
}
if(c == 'a')
{
digitalWrite(LED, HIGH);
}
else if(c == 'b')
{
digitalWrite(LED, LOW);
}
Serial.println(c);
delay (2000);
}
void loop ()
{
if (Serial.available() != 0)
{
x = Serial.read();
c = x ;
}
if(c == 'a')
{
digitalWrite(motor, HIGH);
Serial.print( " print this until c changes value ");
}
else
if(c == 'b')
{
digitalWrite(motor, LOW);
}
delay (2000);
}
Currently, your above sketch is behaving like these: 1. You enter 'a' from the InputBox (with Line ending tab at No line ending option), the L (built-in LED of UNO) becomes ON and the Serial Monitor keeps showing this message " print this until c changes value " in its OutputBox.
2. You enter 'b' from the InputBox, the L and the message " print this until c changes value " go OFF.
3. You enter 'a' from the InputBox, the process of Step-1 repeats.
4. You enter 'u' from the InputBox, the L remains ON; but, the message gets stopped printing.
Under the above circumstances, what you want exactly? Your statement "i want this to run forever , till i enter lets say 'u' from keyboard" is not clear to me. What is 'this' that will keep running until you enter 'h' from the InputBox/keyboard.