Cool! Seems to work really well!
Here is some code set up to change the behavior of the on board LED:
#include <TinyPinChange.h>
#include <SoftSerial.h>
#define RxD 2
#define TxD 3
SoftSerial mySerial(RxD, TxD);
uint8_t VirtualPortNb;
volatile byte p = 0;
void setup()
{
TinyPinChange_Init();
mySerial.begin(38400);
VirtualPortNb=TinyPinChange_RegisterIsr(RxD, softSerialEvent);
TinyPinChange_EnablePin(RxD);
pinMode(1, OUTPUT); //LED on Model A for debugging
}
/* Function called in interruption in case of change on pins */
void softSerialEvent(void)
{
int inByte;
uint8_t PortChange;
PortChange = TinyPinChange_GetPinEvent(VirtualPortNb);
if(PortChange & TinyPinChange_PinToMsk(RxD)) /* Check if we have received something */
{
while(mySerial.available()){//check if there's any data in the serial buffer
inByte = mySerial.read();
if(inByte == 1 || inByte == 2 || inByte == 3)
{
p = inByte;
}
}
}
}
void loop()
{
program(p);
}
void program(byte seq)
{
switch(seq)
{
case 1:
digitalWrite(1, HIGH);
delay(100);
digitalWrite(1, LOW);
delay(100);
break;
case 2:
digitalWrite(1, HIGH);
delay(500);
digitalWrite(1, LOW);
delay(100);
digitalWrite(1, HIGH);
delay(100);
digitalWrite(1, LOW);
delay(100);
break;
case 3:
digitalWrite(1, HIGH);
delay(500);
digitalWrite(1, LOW);
delay(100);
digitalWrite(1, HIGH);
delay(100);
digitalWrite(1, LOW);
delay(100);
digitalWrite(1, HIGH);
delay(100);
digitalWrite(1, LOW);
delay(100);
break;
default:
digitalWrite(1, HIGH);
delay(2000);
digitalWrite(1, LOW);
delay(2000);
break;
}
}