The ATtiny84 might indeed fit the bill.
As for code specific to the 328 I don't know (limited experience here). The sketch is simple as you can see. It could certainly be reduced in size even further by an experienced programmer I'm sure.
How much RAM is required for a small sketch like this?
The sketch doesn't require any special lib inclusions to work. Basically it's blinking a couple of LED's, monitoring a PG signal from a regulator, the position of 3 switches and outputting a couple of different tones on demand.
I have lines for Serial.print() in the code but strictly for debugging while bread boarding. This is not necessary for operation and are currently commented out. I'm using INPUT_PULLUP on two pins. Don't know if that matters.
The ATtiny84 seems to have the required pins. Things get fuzzy after that as to what else is required to port the sketch to that chip. Will I need to include any extra libraries from the IDE to run the Tone() function for example?
/*Dual Transceiver Interface ver 6.0
Sketch version 6.0.1
Control code for:
- Bi-color power LED indication
- Transmitter selection
- Audible alerts of transmitter 2 selected
- Audible low battery alert
- Alert cancel and Alert off functions
Created By Kirk Sceviour
08 Feb 2015
*/
boolean battchange = false; //remains false until a change is detected
boolean powergood = true; //power supply is good
boolean cncl = false; //true for an interval when cancel button pressed
boolean discard = false; //discard all alerts while true
boolean txtwo = false; //transmitter two selected
#define ALERTOFF 5
#define CANCEL 12
#define TXSEL 8
#define redLED 10
#define greenLED 9
#define AUDTONE 6
#define SWCOMM 7
#define PG 4
//for blink without delay functions
#define LED_ON 400 //blink interval millis
#define LED_OFF 3000
unsigned long ms; //time from millis()
unsigned long msLast; //last time the LED changed state
boolean ledState; //current LED state
//for audible functions
unsigned int beepFreq = 440; //frequency of beep
unsigned long beepTime = 200; //duration of beep
//low battery audible indication
unsigned long msBeep;//time from millis()
unsigned long msBeepLast;//last time of beep
unsigned long battBeepPause = 120000; //time between battery beeps
//comm 2 audible indication
unsigned long mstxBeep;
unsigned long mstxBeepLast;
unsigned long txBeepPause = 40000;//time between beeps (normal = 40000)
//for alert cancel function
unsigned long msCncl; //time from millis()
unsigned long msCnclLast;
unsigned long cnclTime = 100000; //duration of cancel mode
void setup()
{
pinMode(CANCEL, INPUT_PULLUP); //Cancel button. LOW when pressed
pinMode(ALERTOFF, INPUT); //To Alerts Off switch. LOW when selected off
pinMode(TXSEL, INPUT_PULLUP); //To TXSEL switch. LOW indicates COMM 2 selected
pinMode(redLED, OUTPUT); //Red power low indication
pinMode(greenLED, OUTPUT); //Green power good indication
pinMode(SWCOMM, OUTPUT);//Output to selector IC. HIGH switches to COMM 2
pinMode(PG, INPUT); //Active LOW PG signal from regulator
pinMode(AUDTONE, OUTPUT); //PWM output to mixer
// Serial.begin(9600); // for debugging
//place unused pins here set to INPUT_PULLUP
}
void loop()
{
msBeep = millis();//time returned from milliseconds
mstxBeep = millis();
msCncl = millis();
ms = millis();
noTone(6);
//read transmitter selector switch
if (digitalRead(TXSEL) == LOW)
{
digitalWrite(SWCOMM, HIGH);//output to selector IC
txtwo = true;//on comm 2
txBeep();
}
else
{
digitalWrite(SWCOMM, LOW);
txtwo = false;
}
if (digitalRead(CANCEL) == LOW) //cancel button pressed
{
cncl = true;//cancel alerts
//Serial.print(" Alerts Cancelled ");
}
//check time elapsed since last event
if (msCncl - msCnclLast > cnclTime)
{
cncl = false; //allow alerts if time is up
msCnclLast = msCncl; //set up for next event
}
//check the No Alerts switch and Cancel modes
if (digitalRead(ALERTOFF) == HIGH || cncl == true)
{//alerts are off or cancel mode active
discard = true;//discard any audible alerts
}
else
{//allow alerts
discard = false;
}
//blink the correct LED
if (digitalRead(PG) == HIGH)//power good
{
digitalWrite(redLED, LOW);//trap red if on
blinkgreenLED();
powergood = true;
}
else//low battery detected
digitalWrite(greenLED, LOW);//trap green if on
blinkredLED();
powergood = false;//low battery
lowbattBeep();//send an audible alert
}
//generate comm 2 audible alert
void txBeep(void)//
{ //check comm 2 selected and cancel mode not active
if (txtwo == true && discard == false)
{
if (mstxBeep - mstxBeepLast > (txBeepPause))//check interval
{//present a double beep
// Serial.print(" on Comm 2 ");//debugging
tone(6, beepFreq, beepTime); //output tone
delay(250);
noTone(6);
tone(6, beepFreq, beepTime);
delay(250);
noTone(6);
mstxBeepLast = mstxBeep;
}
}
}
//generate low battery audible alert
void lowbattBeep(void)
{//check if first indication
if (digitalRead(PG) == LOW && battchange == false)
{//new indication of low battery
// Serial.print(" low batt detect ");//debugging
battchange = true; //change the battery state
}
if (digitalRead(PG) == HIGH && battchange == true)
{//spurious indication so reset.
battchange = false; // reset batt status
noTone(6); //make sure the pin is off
// Serial.print (" batt status reset "); //debugging
}
if (digitalRead(PG) == LOW)
{ //check time since last beep
if (msBeep - msBeepLast > (battBeepPause))
{// Serial.print(" low batt audible alert ");
tone(6, beepFreq, beepTime); //play
delay(200);
noTone(6);
tone(6, 250, beepTime);//play lower tone
delay(200);
noTone(6);
msBeepLast = msBeep;
}
}
}
// LED blink functions. All other code above this.
void blinkgreenLED(void)
{//determine the last time the LED was on
if (ms - msLast > (ledState ? LED_ON : LED_OFF))
{
//switch states if necessary
digitalWrite(greenLED, ledState = !ledState);
msLast = ms;
}
}
void blinkredLED(void)
{
if (ms - msLast > (ledState ? LED_ON : LED_OFF))
{
digitalWrite(redLED, ledState = !ledState);
msLast = ms;
}
}