Awesome! Absolutely no apologies required. I don't feel it was longwinded at all........seems my "wind" has taken two pages to get to where we are here now. Lol
I really appreciate the through response and I'll gets started on the modification and post the completed sketch. Thanks.
int ch1;
int ch2;
int ch3;
int ch4;
const in relayPin =12;
void setup() {
pinMode (4, INPUT) ;
pinMode (5, INPUT) ;
pinMode (6, INPUT) ;
pinMode (7, INPUT) ;
pinMode(relayPin, OUTPUT);
Serial.begin(9600) ;
}
void loop () {
ch1 = pulseIn(4, HIGH, 25000) ;
ch2 = pulseIn(5, HIGH, 25000) ;
ch3 = pulseIn(6, HIGH, 25000) ;
ch4 = pluseIn(7, HIGH, 25000) ;
{
(ch3 >= 1080 && ch3 <= 1900);
}
Serial.print("Channel 1: ") ;
Serial.println(ch1) ;
Serial.print("Channel 2: ") ;
Serial.println(ch2) ;
Serial.print("Channel 3: ") ;
Serial.println(ch3) ;
Serial.print("Channel 4: ") ;
Serial.println(ch4) ;
{
if(ch3 >= 1080 && ch3 <=1100);
}
digitalWrite(relayPin, LOW);
{
else if (ch3 >= 1880 && ch3 <= 1900)
}
digitalWrite (relayPin, HIGH);
{
delay(1000) ;
}
I took the advice and tried a few modifications. Here is my latest try removing "time" and just used ch3.
When I run the compiler it takes me almost to the bottom of the sketch but then I receive a error code of------->
'else' without a previous 'if'
I'm wondering if I have errors in the {bracketing}¿
Thanks!
JasonHohman:
int ch1;
int ch2;
int ch3;
int ch4;
const in relayPin =12;
void setup() {
pinMode (4, INPUT) ;
pinMode (5, INPUT) ;
pinMode (6, INPUT) ;
pinMode (7, INPUT) ;
pinMode(relayPin, OUTPUT);
Serial.begin(9600) ;
}
void loop () {
ch1 = pulseIn(4, HIGH, 25000) ;
ch2 = pulseIn(5, HIGH, 25000) ;
ch3 = pulseIn(6, HIGH, 25000) ;
ch4 = pluseIn(7, HIGH, 25000) ;
{
(ch3 >= 1080 && ch3 <= 1900);
}
Serial.print("Channel 1: ") ;
Serial.println(ch1) ;
Serial.print("Channel 2: ") ;
Serial.println(ch2) ;
Serial.print("Channel 3: ") ;
Serial.println(ch3) ;
Serial.print("Channel 4: ") ;
Serial.println(ch4) ;
{
if(ch3 >= 1080 && ch3 <=1100);
}
digitalWrite(relayPin, LOW);
{
else if (ch3 >= 1880 && ch3 <= 1900)
}
digitalWrite (relayPin, HIGH);
{
delay(1000) ;
}
I took the advice and tried a few modifications. Here is my latest try removing "time" and just used ch3. When I run the compiler it takes me almost to the bottom of the sketch but then I receive a error code of-------> 'else' without a previous 'if' I'm wondering if I have errors in the {bracketing}¿ Thanks!
You are not formatting your if ... else statements correctly. They should be like this:
...
if (condition) {
... do something ... ;
}
else {
... do something else ... ;
}
Here's [url=https://www.arduino.cc/reference/en/language/structure/control-structure/if/]the Reference page[/url] to study.
Here is the working sketch.
int ch1;
int ch2;
int ch3;
int ch4;
const in relayPin =12;
void setup() {
pinMode (4, INPUT) ;
pinMode (5, INPUT) ;
pinMode (6, INPUT) ;
pinMode (7, INPUT) ;
pinMode(relayPin, OUTPUT);
Serial.begin(9600) ;
}
void loop () {
ch1 = pulseIn(4, HIGH, 25000) ;
ch2 = pulseIn(5, HIGH, 25000) ;
ch3 = pulseIn(6, HIGH, 25000) ;
ch4 = pluseIn(7, HIGH, 25000) ;
//{
// (ch3 >= 1080 && ch3 <= 1900);
//}
Serial.print("Channel 1: ") ;
Serial.println(ch1) ;
Serial.print("Channel 2: ") ;
Serial.println(ch2) ;
Serial.print("Channel 3: ") ;
Serial.println(ch3) ;
Serial.print("Channel 4: ") ;
Serial.println(ch4) ;
delay(1000);
if(ch3 >= 1080 && ch3 <=1100) {
digitalWrite(relayPin, LOW);
}
else {
//(ch3 >= 1880 && ch3 <= 1900) {
digitalWrite (relayPin, HIGH);
}
}
Great. You have one line of code, and a couple of braces that doesn't do anything:
{
(ch3 >= 1080 && ch3 <= 1900);
}
Ok I made the adjustments in the code with commenting out the lines.
Maybe that was left over from when I was trying to use "time" in the code.
Thank you!
I'm inserting my DFPlayerMini & amp board onto my breadboard now.
The 12V amp board will be powering my arduino and my arduino is used to power my mp3 module.
So I have been researching UART control from Arduino to DFPlayerMini but I am unsure the best way to code.
I only need to utilize 4 commands to be able to use this mp3 module sufficiently.
I could-------->
I need one channel to cycle between 3 different files.
Potentially 3 hexadecimal strings. 3 position switch.
I also need one channel to signal to restart current audio track. One more hexadecimal string. 2 position switch spring loaded normally off.
But then I also found that I could download a library to add functionality.
As I gather, there would be statements that could be used to avoid the need of sending hexadecimal strings.
Some of the additional functionality might be nice but I would like to keep it as simple as possible.
Any advice of the route I should choose?
Either sending a simple hexadecimal string. (Not quite sure how to send. I dont need the mp3 player to respond back to MCU).
Or find a library that includes all 4 needed functions and avoid the hexadecimal strings.
Thank you very much!