Hi, guys! I just started Arduino few days ago and I'm very into this so I need some help.
I wanted to create something from one place to another place for example: Enter "From 19 to 14".
Another example:
Start: 1
From: 1
To: 14
End: Serial.println('current position')
Here's what I did so far really desperate for help :(...
#include <WString.h>
#include <String.h>
byte mc[] = {1,2};
const byte constant[] = {3,3};
String x;
void setup()
{
Serial.begin(9600);
Serial.println("Startup");
}
void loop()
{
{
if (Serial.available()>10)
{
x=Serial.read();
}
}
if(x.equals('1 to 2'))
{
int pos = (constant[1] - mc[1]);
Serial.println('pos');
}
if(x.equals('2 to 2')) //I'm not really sure if this works or not.. I'm trying to get as many different ways until I find one that works.
{
constant[2]-mc[1];
}
}
uh.. is it like that? still doesn't work sorry I'm pretty new to this.
#include <WString.h>
#include <String.h>
byte mc[] = {1,2};
const byte constant[] = {3,3};
String x;
void setup()
{
Serial.begin(9600);
Serial.println("Startup");
}
void loop()
{
{
if (Serial.available()>10)
{
x=Serial.read();
}
}
if(x ==('1 to 2'))
{
int pos = (constant[1] - mc[1]);
Serial.println('pos');
}
if(x ==('2 to 2')) //I'm not really sure if this works or not.. I'm trying to get as many different ways until I find one that works.
{
int pos; pos<2;pos++;
}
}
String x; is not valid, string x; is, C is case sensitive
if(x ==('1 to 2'))
change to
if(x == "1 to 2")
likewise
if(x ==('2 to 2'))
if(x =="2 to 2")
see what happens
even if it works its a pretty wasteful way to do it, but hey! whatever works for now until you get a grasp on the language
int pos; pos<2;pos++;
not sure whats going on there, what your looking for is something like
for(int pos; pos < 2; pos++)
{
do something
}
if I were a betting man you have knowledge of BASIC right? if so toss it out the window, there is only one language that works like BASIC
PS I am not even sure the above will fix all your issues, serial read, like every other known uart buffer in history fetches one charater at a time so to build a string out of single characters might be more of a pain in the butt than worth it. given the letters A-Z and numbers 0-9, gives you 36 unique values at a very simple level of understanding ... 0-9 = 1-10, A-Z= 11-26... something to think about, I have used it before (base 36) with great results.