Hi guys. I'm trying to input some simple maths equation (for example: 3*2) into the serial monitor to make my led blink the amount of times equal to that equation answer however, it only blinks correctly when I input a number or a sum. How can I make so that any simple maths equation works?
It has to use the cycle for() because it is for university and my teacher is asking me to do with it.
Here's my code
int i, pin1=13;
void setup()
{
pinMode(pin1, OUTPUT);
Serial.begin(9600);
}
void loop()
{
{
int x = Serial.parseInt();
for (i=0; i<x;i++)
{
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
delay(200);
}
}
}
[code]
Thanks for replying but I think that's not what I need. It's too complicated for my needs and I didn't even learn most of the things in the code. I think you must've read the post wrong.
Tortels:
It's too complicated for my needs and I didn't even learn most of the things in the code.
It's pretty basic code, you could lookup each function to learn it,
which you should if this is homework anyway.
I doubt that you can implement "that any simple maths equation works" with less or simpler code.
Reading a full line and interpreting it is a very easy and robust method for serial input.
It does not block, so you could easily integrate it in the 'blink without delay' example.