This is my effort at making a sketch.
The idea is that it will be controlled from the PC.
I send it commands and it changes the frequency.
Ok, re-think. Instead of sending it up/down commands to change the frequency, I just send it the actual frequency.
Either way I am stuck.
This is the sketch so far:
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop()
{
// put your main code here, to run repeatedly:
int tone_frequency;
if (Serial.available() > 0)
{
char dir = Serial.read();
char num1 = Serial.read();
char num2 = Serial.read();
Serial.print ("Dir ");
Serial.println (dir);
Serial.print("Num1 ");
Serial.println (num1);
Serial.print("Num2 ");
Serial.println (num2);
}
}
I am getting this when I run it and send a command: (which is +.1)
Dir +
Num1 ÿ
Num2 ÿ
Dir .
Num1 ÿ
Num2 ÿ
Dir 0
Num1 ÿ
Num2 ÿ
Dir 1
Num1 ÿ
Num2 ÿ
As you can see there are "dummy" lines between them.
Dunno why.
I have used this sort of stuff in another sketch and it seems to work.
Anyone - please.
Ok, I learned something:
I need to see the "delimiter". I was always getting a "7" at the end.
So I made is to this sketch:
int frequency1;
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop()
{
// put your main code here, to run repeatedly:
int tone_frequency;
if (Serial.available() > 0)
{
//
frequency1 = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
//run_time_hr = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
if(Serial.read() == ';')
{
Serial.print ("The frequency you entered is ");
Serial.println (frequency1);
}
}
}
But now it doesn't accept anything or echo anything back.
Say I enter 22;
I don't get anything back.
Stuck but trying.