Jun 222017
 

Python3 code is below…

also available at this Gitlab link

https://gitlab.com/Alex-rtnVFRmedia/pagertest2

# control the Arduino RF22 pager TX # modified ON1ARF code # # 2017-06-23 Alex The Engineer # The Rat's Nest, Ipswich UK # # import serial import pprint import sys from colorconsole import terminal from colored import fg, bg, attr import readline # global colours res=attr('reset') # tty open now coded as a function # # colored module used here instead of colorconsole/screen object # just in case there isn't a global screen object available # def page(ttydev,capcode,function,repeats,message): # # create msg bytearray (NB: there should be more error # checking here # msg=(b'P ') msg+=(b'%07d' % capcode)+(b' ') msg+=(b'%01d' % function)+(b' ') msg+=(b'%01d' % repeats)+(b' ') msg+=(message)+(b'\r') print (fg(80),bg(0x12),'** opening tty:',ttydev+res) # serial port open with error checking this time try: ser = serial.Serial(ttydev, timeout=3) except serial.SerialException: print(res) sys.exit("** ERROR: cannot open tty\n\n") # if we got here everything is OK # RTS/DTR does not actually need to be flipped # as opening the tty does that anyway # which saves some time starting up the arduino comms # ser.setRTS(True) # ser.setRTS(False) # # get the lines from the buffer print (fg(0x0b),bg(0x15),'** tty open OK: >>check TX<<'+res) ibuf = ser.readlines() print (fg(202)) #pprint.pprint(ibuf) print (' ibuf[0] :',ibuf[0]) print (' ibuf[-1] :',ibuf[-1]) # check to see what came down comms line is expected if ibuf[0] != (b'RF22 init OK\r\n'): print(res) sys.exit("** ERROR: RF22 init error\n\n") if ibuf[-1] != (b'F <freqmhz> <freq100Hz>\r\n'): print(res) sys.exit("** ERROR: RF22 comms error\n\n") # if TX has correctly initialised now send message ser.write(msg) # get a line back from TTY, it should be exactly same as msg # but with a \n after it # if it hasn't something has gone wrong check=ser.readline() print(fg(0x50),'<< from tty:',fg(0x72),bg(0x08),check,res,fg(0x52)) if check != (msg+b'\n'): print(res) sys.exit("** ERROR: pager comms error\n\n") print (' ++ comms to pager TX OK ++') # get data returned over comms link # and now echo it with some pretty colours 🙂 colindex=0x70 while True: data=ser.readline() # only print it if a sending confirmation if data==(b'POCSAG SEND\r\n'): print (fg(0x30),'<< from tty:',fg(colindex),data) colindex += 1 if data==(b'F <freqmhz> <freq100Hz>\r\n'): break # all done, close tty print (fg(0x28),'** message sent correctly **\n') ser.close() def header(scr): scr = terminal.get_terminal(conEmu=False) scr.clear() scr.xterm256_set_fg_color(0x52) scr.xterm256_set_bk_color(0x08) scr.print_at(2,0,"rtn telecom : pagertest 1.00") scr.xterm256_set_bk_color(0) scr.gotoXY(2,3) scr.xterm256_set_fg_color(0x20) print('capcode:') scr.xterm256_set_bk_color(0x08) scr.xterm256_set_fg_color(0x78) scr.gotoXY(10,3) print(' ') scr.xterm256_set_bk_color(0) scr.gotoXY(20,3) scr.xterm256_set_fg_color(0x20) print('alert:') scr.xterm256_set_bk_color(0x08) scr.xterm256_set_fg_color(0x78) scr.gotoXY(26,3) print(' ') scr.xterm256_set_bk_color(0) scr.gotoXY(2,5) scr.xterm256_set_fg_color(0x20) print('message:') scr.xterm256_set_bk_color(0x08) scr.xterm256_set_fg_color(0x78) scr.gotoXY(10,5) print(' ') scr.xterm256_set_bk_color(0) scr.gotoXY(0,9) scr.xterm256_set_fg_color(0x28) # to be developed, input capcode def get_capcode(scr,default): pass # display capcode in input box def disp_capcode(scr,capcode): scr.xterm256_set_bk_color(0x08) scr.xterm256_set_fg_color(0x78) scr.gotoXY(10,3) print (str((b'%07d' % capcode),'utf-8')) scr.xterm256_set_bk_color(0) # display alert code in input box def disp_alert(scr,alert): scr.xterm256_set_bk_color(0x08) scr.xterm256_set_fg_color(0x78) scr.gotoXY(26,3) print (str((b'%01d' % alert),'utf-8')) scr.xterm256_set_bk_color(0) # display message in input box def disp_msg(scr,message): scr.xterm256_set_bk_color(0x08) scr.xterm256_set_fg_color(0x78) scr.gotoXY(10,5) print (str(message,'utf-8')) scr.xterm256_set_bk_color(0) scr.gotoXY(0,9) # # main code now starts here # # initialise the screen # # 2017-06-23: now accepts interactive input of message # # a blank line transmits the hardcoded message # # 'q' exits the code # while True: # refresh the header screen = terminal.get_terminal(conEmu=False) header(screen) # message now split into capcode, function (0-3), repeats # and 40 character bytearray # # hardcoded values # capcode = 20008 function = 2 repeats = 1 message = b'rtn: miauw naar de maan!<<<pagertest>>>' ttydev="/dev/ttyACM0" # display the capcode and alert that are currently hardcoded # but leave the msg box blank as it now accepts user input # disp_capcode(screen,capcode) disp_alert(screen,function) # # create a quick and dirty coloured prompt for the input # screen.gotoXY(2,7) screen.xterm256_set_fg_color(0x38) print('------>') screen.gotoXY(10,7) screen.xterm256_set_fg_color(0x68) # # this uses readline so has some basic editing functions # # anything over 40 character is clipped # ms1=input() if ms1 !='': message=ms1[0:40].encode('utf-8') if ms1 =='q': break # # display the msg in the top box and transmit it # disp_msg(screen,message) page(ttydev,capcode,function,repeats,message) # # terminate script and reset all the console colours # print (fg(0xc8),'\n++ Script completed sucessfully ++\n',res)
pagertest2.py
Feb 062016
 

Since putting this project on Youtube I’ve had a surprising amount of interest from across the world about the modifications I made to the original code from ON1ARF ( a radioamateur in België) to allow 1200 and 2400 bps pager transmissions as well as the default 512bps (I wanted to use the circuit to test commercial POCSAG pager receivers used at one site at my work).

The original code is here

https://github.com/on1arf/pocsag

To get 1200 and 2400 bps you must alter the radiohead libraries it depends on.

Two files must change – the first is RH_RF22.cpp. The code snippet is below (cut and paste this into your editor)

// These are indexed by the values of ModemConfigChoice // Canned modem configurations generated with // http://www.hoperf.com/upload/rf/RH_RF22B%2023B%2031B%2042B%2043B%20Register%20Settings_RevB1-v5.xls // Stored in flash (program) memory to save SRAM PROGMEM static const RH_RF22::ModemConfig MODEM_CONFIG_TABLE[] = { { 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x00, 0x08 }, // Unmodulated carrier { 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x33, 0x08 }, // FSK, PN9 random modulation, 2, 5 // All the following enable FIFO with reg 71 // 1c, 1f, 20, 21, 22, 23, 24, 25, 2c, 2d, 2e, 58, 69, 6e, 6f, 70, 71, 72 // FSK, No Manchester, Max Rb err <1%, Xtal Tol 20ppm { 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x22, 0x08 }, // 2, 5 { 0x1b, 0x03, 0x41, 0x60, 0x27, 0x52, 0x00, 0x07, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x22, 0x3a }, // 2.4, 36 { 0x1d, 0x03, 0xa1, 0x20, 0x4e, 0xa5, 0x00, 0x13, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x27, 0x52, 0x2c, 0x22, 0x48 }, // 4.8, 45 { 0x1e, 0x03, 0xd0, 0x00, 0x9d, 0x49, 0x00, 0x45, 0x40, 0x0a, 0x20, 0x80, 0x60, 0x4e, 0xa5, 0x2c, 0x22, 0x48 }, // 9.6, 45 { 0x2b, 0x03, 0x34, 0x02, 0x75, 0x25, 0x07, 0xff, 0x40, 0x0a, 0x1b, 0x80, 0x60, 0x9d, 0x49, 0x2c, 0x22, 0x0f }, // 19.2, 9.6 { 0x02, 0x03, 0x68, 0x01, 0x3a, 0x93, 0x04, 0xd5, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x09, 0xd5, 0x0c, 0x22, 0x1f }, // 38.4, 19.6 { 0x06, 0x03, 0x45, 0x01, 0xd7, 0xdc, 0x07, 0x6e, 0x40, 0x0a, 0x2d, 0x80, 0x60, 0x0e, 0xbf, 0x0c, 0x22, 0x2e }, // 57.6. 28.8 { 0x8a, 0x03, 0x60, 0x01, 0x55, 0x55, 0x02, 0xad, 0x40, 0x0a, 0x50, 0x80, 0x60, 0x20, 0x00, 0x0c, 0x22, 0xc8 }, // 125, 125 // { 0x2b, 0x03, 0xa1, 0xe0, 0x10, 0xc7, 0x00, 0x09, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x04, 0x32, 0x2c, 0x22, 0x04 }, // 512 baud, FSK, 2.5 Khz fd for POCSAG compatibility { 0x27, 0x03, 0xa1, 0xe0, 0x10, 0xc7, 0x00, 0x06, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x09, 0xd5, 0x2c, 0x22, 0x07 }, // 1200 baud, FSK, 4.5 Khz fd for POCSAG compatibility // { 0x27, 0x03, 0xa1, 0xe0, 0x10, 0xc7, 0x00, 0x06, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x04, 0x32, 0x2c, 0x22, 0x07 }, // 512 baud, FSK, 4.5 Khz fd for POCSAG compatibility // 2400 bps { 0x27, 0x03, 0xa1, 0xe0, 0x10, 0xc7, 0x00, 0x06, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x22, 0x07 },// 2400 baud, FSK, 4.5 Khz fd for POCSAG compatibility // GFSK, No Manchester, Max Rb err <1%, Xtal Tol 20ppm // These differ from FSK only in register 71, for the modulation type { 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x23, 0x08 }, // 2, 5 { 0x1b, 0x03, 0x41, 0x60, 0x27, 0x52, 0x00, 0x07, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x23, 0x3a }, // 2.4, 36 { 0x1d, 0x03, 0xa1, 0x20, 0x4e, 0xa5, 0x00, 0x13, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x27, 0x52, 0x2c, 0x23, 0x48 }, // 4.8, 45 { 0x1e, 0x03, 0xd0, 0x00, 0x9d, 0x49, 0x00, 0x45, 0x40, 0x0a, 0x20, 0x80, 0x60, 0x4e, 0xa5, 0x2c, 0x23, 0x48 }, // 9.6, 45 { 0x2b, 0x03, 0x34, 0x02, 0x75, 0x25, 0x07, 0xff, 0x40, 0x0a, 0x1b, 0x80, 0x60, 0x9d, 0x49, 0x2c, 0x23, 0x0f }, // 19.2, 9.6 { 0x02, 0x03, 0x68, 0x01, 0x3a, 0x93, 0x04, 0xd5, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x09, 0xd5, 0x0c, 0x23, 0x1f }, // 38.4, 19.6 { 0x06, 0x03, 0x45, 0x01, 0xd7, 0xdc, 0x07, 0x6e, 0x40, 0x0a, 0x2d, 0x80, 0x60, 0x0e, 0xbf, 0x0c, 0x23, 0x2e }, // 57.6. 28.8 { 0x8a, 0x03, 0x60, 0x01, 0x55, 0x55, 0x02, 0xad, 0x40, 0x0a, 0x50, 0x80, 0x60, 0x20, 0x00, 0x0c, 0x23, 0xc8 }, // 125, 125 // OOK, No Manchester, Max Rb err <1%, Xtal Tol 20ppm { 0x51, 0x03, 0x68, 0x00, 0x3a, 0x93, 0x01, 0x3d, 0x2c, 0x11, 0x28, 0x80, 0x60, 0x09, 0xd5, 0x2c, 0x21, 0x08 }, // 1.2, 75 { 0xc8, 0x03, 0x39, 0x20, 0x68, 0xdc, 0x00, 0x6b, 0x2a, 0x08, 0x2a, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x21, 0x08 }, // 2.4, 335 { 0xc8, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x29, 0x04, 0x29, 0x80, 0x60, 0x27, 0x52, 0x2c, 0x21, 0x08 }, // 4.8, 335 { 0xb8, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x28, 0x82, 0x29, 0x80, 0x60, 0x4e, 0xa5, 0x2c, 0x21, 0x08 }, // 9.6, 335 { 0xa8, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x28, 0x41, 0x29, 0x80, 0x60, 0x9d, 0x49, 0x2c, 0x21, 0x08 }, // 19.2, 335 { 0x98, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x28, 0x20, 0x29, 0x80, 0x60, 0x09, 0xd5, 0x0c, 0x21, 0x08 }, // 38.4, 335 { 0x98, 0x03, 0x96, 0x00, 0xda, 0x74, 0x00, 0xdc, 0x28, 0x1f, 0x29, 0x80, 0x60, 0x0a, 0x3d, 0x0c, 0x21, 0x08 }, // 40, 335 };
RH_RF22.cpp

Also the header file RH_RF22.h must change so the modemconfig table has values that reflect the changed modulation schemes.

typedef enum { UnmodulatedCarrier = 0, ///< Unmodulated carrier for testing FSK_PN9_Rb2Fd5, ///< FSK, No Manchester, Rb = 2kbs, Fd = 5kHz, PN9 random modulation for testing FSK_Rb2Fd5, ///< FSK, No Manchester, Rb = 2kbs, Fd = 5kHz FSK_Rb2_4Fd36, ///< FSK, No Manchester, Rb = 2.4kbs, Fd = 36kHz FSK_Rb4_8Fd45, ///< FSK, No Manchester, Rb = 4.8kbs, Fd = 45kHz FSK_Rb9_6Fd45, ///< FSK, No Manchester, Rb = 9.6kbs, Fd = 45kHz FSK_Rb19_2Fd9_6, ///< FSK, No Manchester, Rb = 19.2kbs, Fd = 9.6kHz FSK_Rb38_4Fd19_6, ///< FSK, No Manchester, Rb = 38.4kbs, Fd = 19.6kHz FSK_Rb57_6Fd28_8, ///< FSK, No Manchester, Rb = 57.6kbs, Fd = 28.8kHz FSK_Rb125Fd125, ///< FSK, No Manchester, Rb = 125kbs, Fd = 125kHz FSK_Rb_1200Fd4_5, ///< FSK, No Manchester, Rb = 1200bs, Fd = 4.5kHz, for POCSAG compatibility // FSK_Rb_512Fd4_5, ///< FSK, No Manchester, Rb = 512bs, Fd = 4.5kHz, for POCSAG compatibility FSK_Rb_2400Fd4_5, ///< FSK, No Manchester, Rb = 2400bs, Fd = 4.5kHz, for POCSAG compatibility GFSK_Rb2Fd5, ///< GFSK, No Manchester, Rb = 2kbs, Fd = 5kHz GFSK_Rb2_4Fd36, ///< GFSK, No Manchester, Rb = 2.4kbs, Fd = 36kHz GFSK_Rb4_8Fd45, ///< GFSK, No Manchester, Rb = 4.8kbs, Fd = 45kHz GFSK_Rb9_6Fd45, ///< GFSK, No Manchester, Rb = 9.6kbs, Fd = 45kHz GFSK_Rb19_2Fd9_6, ///< GFSK, No Manchester, Rb = 19.2kbs, Fd = 9.6kHz GFSK_Rb38_4Fd19_6, ///< GFSK, No Manchester, Rb = 38.4kbs, Fd = 19.6kHz GFSK_Rb57_6Fd28_8, ///< GFSK, No Manchester, Rb = 57.6kbs, Fd = 28.8kHz GFSK_Rb125Fd125, ///< GFSK, No Manchester, Rb = 125kbs, Fd = 125kHz OOK_Rb1_2Bw75, ///< OOK, No Manchester, Rb = 1.2kbs, Rx Bandwidth = 75kHz OOK_Rb2_4Bw335, ///< OOK, No Manchester, Rb = 2.4kbs, Rx Bandwidth = 335kHz OOK_Rb4_8Bw335, ///< OOK, No Manchester, Rb = 4.8kbs, Rx Bandwidth = 335kHz OOK_Rb9_6Bw335, ///< OOK, No Manchester, Rb = 9.6kbs, Rx Bandwidth = 335kHz OOK_Rb19_2Bw335, ///< OOK, No Manchester, Rb = 19.2kbs, Rx Bandwidth = 335kHz OOK_Rb38_4Bw335, ///< OOK, No Manchester, Rb = 38.4kbs, Rx Bandwidth = 335kHz OOK_Rb40Bw335 ///< OOK, No Manchester, Rb = 40kbs, Rx Bandwidth = 335kHz } ModemConfigChoice;
RH_RF22.h

the rest can then be used as normal – remember to alter the main Arduino sketch code to select these new bps rates.

NB: I am based in the UK/Europe; we always use wide deviation for POCSAG signals (although much other PMR traffic is now on narrow deviation).

If your country’s Communications Ministry requires narrow deviation to be used you will have to recalculate the modem settings using the spreadsheet referred to in the library files. (Its not as bad as it might seem; I had to use it to get the 1200/2400bps settings and I am not an RF nor a coding expert by any means)

 

Apr 112014
 

this should be the code
/* Control a sony receiver via Arduino and IR
/ auto mute when door is open
/ using reed swich on door
/ 2011/2012/2013/2014
/ Alex@The Rats Nest, Ipswich, UK
/ IR code taken from http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
/ and remote codes from here http://lirc.sourceforge.net/remotes/sony/RM-AAU014
/
/
/ also 4 x buttons, for vol up/down, toggle green/red led (as they can get out of sync)
/ and force mute
/ NB: This receiver uses 15 bit protocol
/ and only needs 50ms delay after each command sent twice
/ per button press
*/

// 2013-11-05 updated
// new debounce library added
// now used for door contact

// LEDS index

// 00 -(pin 13) -red
// 01 -(pin 11) - green
// 02 -(pin 10) watchdog LED (amber)
// 03 -(pin 7) trigger LED (blue)
// 04 -(pin 5) telephone LED

// 2013-11-23 - added control for relays
// 2013-12-14 - removed serial port writes
// to see if the startup is cleaner
// 2014-01-13 - corrected comments on pin layout
// reset problem was caused by hardware issue!
// 2014-02-15 - added extra output for telephone LED
// 2014-03-31 - recoded due to change in bounce library

const int buttonPins[4] = {2,4,8,9};
const int ledPins[5] = {13,11,10,7,5};
const int reedPin= 12 ; // reed switch
const int relay1Pin = 6 ;

// this ia LDR brightness if telephone strobe is on

const int strobeVal = 700 ;

const int btnDelay = 20 ; // button deley
const int reedDelay= 25 ; //

// define the constants for the remote code
// and timing delays

#define MUTE 0x140C
#define VOLUME_UP 0x240C
#define VOLUME_DOWN 0x640C

#define IR_delay1 5
#define IR_delay2 5
#define REPEATS 2
#define REED_delay 50

#define LONGBARK 500
#define YAP 50

#include

// beware this lib name is changed

#include

// global declarations & vars

IRsend irsend;

Bounce btn01 = Bounce();
Bounce btn02 = Bounce();
Bounce btn03 = Bounce();
Bounce btn04 = Bounce();
Bounce reed = Bounce();

int incomingbyte = 0;
int ledState[5] = { HIGH, LOW, HIGH, HIGH, LOW};
int btnChange[4] = { LOW, LOW, LOW, LOW };
int reedChange = LOW ;
int btnState[4] = { HIGH, HIGH, HIGH, HIGH}; // as these are pulled up (active low)
int reedState=HIGH ;
int reedTime= 0 ;
int iptChange = HIGH ;
int trigLedLatch = LOW ;
int muteState = LOW ;
int relay2State = LOW ;
int ldrValue = LOW ;
unsigned long previousMillis = 0;
unsigned long lastMuteTime = 0 ;
unsigned long trigLedTime = 0 ;
long barkInterval = LONGBARK ; // bark the watchdog LED every 500 ms
long trigInterval = 125 ; // flash command received LED

void setup()
{

pinMode(buttonPins[0], INPUT);
pinMode(buttonPins[1], INPUT);
pinMode(buttonPins[2], INPUT);
pinMode(buttonPins[3], INPUT);
pinMode(reedPin, INPUT);

btn01.attach(buttonPins[0]);
btn02.attach(buttonPins[1]);
btn03.attach(buttonPins[2]);
btn04.attach(buttonPins[3]);

btn01.interval(btnDelay);
btn02.interval(btnDelay);
btn03.interval(btnDelay);
btn04.interval(btnDelay);

reed.attach(reedPin);

pinMode(ledPins[0], OUTPUT);
pinMode(ledPins[1], OUTPUT);
pinMode(ledPins[2], OUTPUT);
pinMode(ledPins[3], OUTPUT);
pinMode(ledPins[4], OUTPUT);
pinMode(relay1Pin, OUTPUT);

getButtons();

// initialise leds

ledEmit(5);

}

void loop()
{

iptChange = LOW ;
getButtons();

// bark the watchdog LED

unsigned long currentMillis = millis();

if (currentMillis - previousMillis > barkInterval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
ledState[3] = !ledState[3] ;
}

// get LDRvalue

ldrValue = analogRead (A0) ;

// green button

if ( btnChange[0] && btnState[0] ) {
// ledState[2] = !ledState[2] ;
ledState[0] = HIGH ;

ledState[1] = LOW ;
iptChange = HIGH ;
// Serial.println("btn 00 state change - green light mute off");
// Serial.println("Relay OFF");
barkInterval = LONGBARK ; // long bark
muteState = LOW ;

}

// red button

if ( btnChange[1] && btnState[1] ) {
// ledState[2] = !ledState[2] ;
ledState[0] = LOW ;
ledState[1] = HIGH ;
// Serial.println("btn 01 state change - red light mute ON");
// Serial.println("relay1 ON");
iptChange = HIGH ;
// irEmit(MUTE,REPEATS);
barkInterval = YAP ; // "yap" if redlight is on-*+
muteState = HIGH ;
}

if ( btnChange[2] && btnState[2]) {
// ledState[2] = !ledState[2] ;
// Serial.println("btn3 state change");
// Serial.println("sending VOL dOWN to IR led");
iptChange = HIGH ;
irEmit(VOLUME_DOWN,REPEATS);
}

if ( btnChange[3] && btnState[3]) {
// ledState[2] = !ledState[2] ;
// Serial.println("btn4 state change");
// Serial.println("sending VOL UP to IR led");
iptChange = HIGH ;
irEmit(VOLUME_UP,REPEATS);
}

// check reed, beware as this will be high when the door is open

if ( reedChange ) {
iptChange = HIGH ;
if ( reedState) {
ledState[0] = LOW ;
ledState[1] = HIGH ;
muteState = HIGH ;
barkInterval = YAP ;

// Serial.println("door OPEN - red/MUTE");
// Serial.println("sending MUTE to IR led");
//
// irEmit(MUTE,REPEATS);
}
if ( !reedState) {
ledState[0] = HIGH ;
ledState[1] = LOW ;
muteState = LOW ;
barkInterval = LONGBARK ;
// Serial.println("door CLOSED - red/sound through");
}
}

// check for telephone strobe

if ( ldrValue > strobeVal ) {
// ledState[2] = HIGH ;
iptChange = HIGH ;
ledState[4] = HIGH ;
// Serial.print("A0 val:");
// Serial.println(ldrValue);
}

// check for input changes and send them to serialport
// latch the trigger LED on for enough time (as the actual input change is
// only a few ms

if ( iptChange) {

trigLedLatch = HIGH ;
ledState[2] = HIGH ;
trigLedTime = millis() ;
}

currentMillis = millis();

if ( currentMillis - trigLedTime > trigInterval ) {
ledState[2] = LOW ;
trigLedLatch = LOW ;
}

ledEmit(5);
digitalWrite (relay1Pin, muteState );
}

// Functions now go here at end of sketch

void irEmit(int code, int repeats)
{
for (int i = 0 ; i < (repeats) ; i++) { irsend.sendSony(code, 15); delay(IR_delay1); irsend.sendSony(code, 15); delay(IR_delay1); irsend.sendSony(code, 15); delay(IR_delay1); irsend.sendSony(code, 15); delay(IR_delay2); } } void ledEmit(int maxLeds) { for (int i = 0 ; i < (maxLeds) ; i++) { digitalWrite(ledPins[i],ledState[i]); } } void getButtons() { btnChange[0] =btn01.update(); btnChange[1] =btn02.update(); btnChange[2] =btn03.update(); btnChange[3] =btn04.update(); reedChange =reed.update(); btnState[0] = !(btn01.read()); btnState[1] = !(btn02.read()); btnState[2] = !(btn03.read()); btnState[3] = !(btn04.read()); reedState = reed.read(); // :) // reedTime = reed.duration(); }