I'm stuck and could use some help.
I'm attempting to read a toggle switch's (message_switch) position, and based on whether it is HIGH or LOW, to send a different message out on a particular pin. The message being sent is stored as an array in const char beacon_call_1 and beacon_call_2.
I have the switch set up correctly and verify that the Arduino is reading the High/Low correctly.
My trouble is when I try and set a variable equal to the array, I get an expected primary-expression token error. I believe that the issue I'm running into is because I'm trying to pass different types, but I can't remember how to properly set it up...
To say this in a different way: depending on the value of the switch, I want to make the variable my_message set equal to a different message. On = beacon_call_1 and Off = beacon_call_2.
beacon_call[] will then be set equal to my_message.
Thank you for any help.
//
#include <Morse.h>
#define blue 7 // Blue Led Pin
#define green 8 // Green LED Pin
#define red 9 // Red Led Pin
const int on_off_switch_pin = 4;
const int message_switch = 5;
const int mode = 1; // Mode 0 = Beacon 1 = Foxhunt
char my_message ;
const char beacon_call_1[] = "MY DOG ATE MY HOMEWORK"; // Message to Send
const char beacon_call_2[] = "TEST"; // Message to Send
const int key_speed = 20; // CW send speed
int interval = 2; // Timer interval in seconds - This is the amount of time between the end of the transmission and the repeat of it.
int repeat = 1; // Repeat message time in seconds - must be a minimum of 1
const int beep_pin = 11; // Pin for CW tone
int key_pin = 12; // Pin for PTT/Rig Key
long end_time; // Foxhunt timing
char c; // Character to send
bool first_pass = true; // Flag to tell us this is the first time through
unsigned long offset = 0L; // Timer value
Morse morse(beep_pin, key_speed, 1); // Set up the Morse Library for use
int msg_length; // variable to hold the size of the message text array
// Timer function - returns the time in seconds since last Timer Reset
unsigned long Timer()
{
return (millis()- offset)/1000; // return time in seconds
}
// Timer Reset function
void TimerReset(unsigned long val = 0L)
{
offset = millis() - val;
}
void setup()
{
pinMode(on_off_switch_pin, INPUT);
pinMode(message_switch, INPUT);
digitalRead(message_switch);
if(message_switch == HIGH){
my_message = beacon_call_1[];
}
else{
my_message = beacon_call_2[];
}
char beacon_call[] = my_message;
pinMode(key_pin, OUTPUT); // set PTT/Key pin to output
pinMode(red, OUTPUT); // Set up the LED pins for output
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
digitalWrite(key_pin,LOW); // Turn off the PTT/Key relay
ledOff(); // Turn off the LED
delay(5000); // Wait 5 seconds
TimerReset(); // Reset the Timer to zero
ledGreen(); // Turn on the Green LED to indicate Beacon/Keyer ready
msg_length =(sizeof(beacon_call))-1; // Calculate the size of the message text array
} // End Setup Loop
void loop() // Main Program Loop
{
if(digitalRead(on_off_switch_pin) == HIGH){
if (Timer() > interval | first_pass) // Send if the Timer has expired or if this is the first time through
{
first_pass = false; // Set the flag to off
if (mode == 0) // Set the Key mode and LED for Beacon or Foxhunt
{
// Set Beacon Mode
Morse(key_pin, key_speed, 0); // Set up to key the Relay
ledBlue(); // Turn on the Blue LED to indicate Beacon Message Transmitting
} else {
// Set Foxhunt Mode
Morse(beep_pin, key_speed, 1); // Set up to send modulated CW
ledRed(); // Turn on the Red LED to indicate Foxhunt Message Transmitting
digitalWrite(key_pin, HIGH); // Key the PTT
}
end_time = Timer() + repeat; // If we're in Foxhunt mode, repeat the message until the repeat time has expired
while(Timer() < end_time) // Check to make sure repeat timer has not expired (Foxhunt Mode)
{
for (int x = 0; x < msg_length; x++) // Send the message in the beacon_call character array one character at a time
{
c = beacon_call[x]; // Get the next letter to send
morse.send(c); // Send it in CW
}
if (mode == 1) // Send a space if we're in Foxhunt mode to separate messages
{
morse.send(char(32));
} else {
end_time = Timer()-1;
}
}
digitalWrite(key_pin, LOW); // Make sure the PTT is off
ledGreen(); // Turn the LED Green to indicate Ready condition
TimerReset(); // Reset the timer to restart the Interval between messages
}
}
else{};
}
// LED Off function
void ledOff()
{
digitalWrite(red, LOW); // Set all RBG LED pins High (Off)
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
}
// RED LED ON function
void ledRed()
{
digitalWrite(red, HIGH); // Turn on the RGB Red LED On
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
}
// Green LED ON function
void ledGreen()
{
digitalWrite(red, LOW);
digitalWrite(green, HIGH); // Turn on the RGB Green LED On
digitalWrite(blue, LOW);
}
// Blue LED ON function
void ledBlue()
{
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, HIGH); // Turn on the RGB Blue LED On
}