tom321
September 8, 2022, 2:39pm
1
Hi
I have a beep from Uy but I need it from Uythr
void setup() {
Serial.begin(115200);
}
void loop() {
int Ux = analogRead(PA0);
int Uy = analogRead(PA1);
//++++++++++++++++++
int Uythr = Uy; // ????????????????????????????????????????????????
//+++++++++++++++++++
Serial.print(" Ux = ");
Serial.print(Ux);
Serial.print(" Uy= ");
Serial.print(Uy);
if (Ux > 2040) //
{
Serial.print(" Uythr = ");
Serial.println(Uythr);
}
else
{
Serial.print(" Uythr = ");
Serial.println(10);
}
////////////////
if( Uythr > 2020 && Uythr < 2030)
{
digitalWrite(PC13, 0);
tone (PA3, 4400);
}
else
{
digitalWrite(PC13, 1);
noTone(PA3);
}
////////////////
delay (100);
}
Which Arduino are you using?
Good to know, thanks. Now, does analogRead ever return values between 2020 and 2030?
if( Uythr > 2020 && Uythr < 2030)
tom321
September 8, 2022, 2:52pm
5
yes
int Uythr = Uy;
if (Ux > 2040)
those two line need to be somehow combined
int Uythr = Uy if (Ux > 2040) // ??
Excellent!
Should beep in those cases, provided you have something connected to PA3, that actually beeps. But if another value immediately comes along that is NOT in that range, the tone will be shut off.
Try this:
if( Uythr > 2020 && Uythr < 2030)
{
digitalWrite(PC13, 0);
tone (PA3, 4400);
delay(200);
}
tom321
September 8, 2022, 3:21pm
7
if( Uythr > 2020 && Uythr < 2030)
{
digitalWrite(PC13, 0);
tone (PA3, 4400);
delay(200);
There is no difference between those two, they respond the same way
if( Uy> 2020 && Uy < 2030)
{
digitalWrite(PC13, 0);
tone (PA3, 4400);
delay(200);
There is 2 conditions for Uythr
A . Uythr = Uy
B. A= true if Ux > 2040
Indeed, the two snippets are identical.
Like this?
void setup()
{
Serial.begin(115200);
}
void loop()
{
int Ux = analogRead(PA0);
int Uy = analogRead(PA1);
int Uythr;
Serial.print(" Ux = ");
Serial.print(Ux);
Serial.print(" Uy= ");
Serial.print(Uy);
if (Ux > 2040) //
{
Uythr = Uy;
Serial.print(" Uythr = ");
Serial.println(Uythr);
}
else
{
Serial.print(" Uythr = ");
Serial.println(10);
}
////////////////
if ( Uythr > 2020 && Uythr < 2030)
{
digitalWrite(PC13, 0);
tone (PA3, 4400);
}
else
{
digitalWrite(PC13, 1);
noTone(PA3);
}
////////////////
delay (100);
}
Also I don't understand why you have this?
else
{
Serial.print(" Uythr = ");
Serial.println(10);
}
tom321
September 8, 2022, 6:27pm
10
Thanks, it is working.
it is easier to read serial monitor
But it prints "Uythr = 10" when Uythr doesn't equal 10.
OK . Just seems weird to print it as having a value it doesn't have. I don't see the utility in that.
system
Closed
March 7, 2023, 8:19pm
14
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.