// https://github.com/GreyGnome/EnableInterrupt
// could be used for edge-triggered interrupts on any pin for pulse counting
+// Here I use a simplified version of my DS18B20 code from years back. This starts the conversion at the END
+// of the code - so the first value is rubbish - but then there are no delays. On the assumption of one chip
+// per pin, no need for search either!
#include <Servo.h> /// note that if you use ANY servo, you lose PWM on pins 9 and 10.
#include <avr/pgmspace.h>
-#define EEPROM_USE_QTECH 2
#define READ_INPUT_PULLUP 3
const PROGMEM uint8_t ledTable[256] = // Nano is so pathetically short of RAM I have to do this!
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4,
Servo myservos[14]; // just for ease - so use any pin from 3 to 13... bit of waste but so what.
+// Here's the Dallas code
+ for (i=0;i<2; i++) data[i]=ds.read();
+ result=(data[1]<<8)|data[0];
+ //result>>=4; if (data[1]&128) result |=0xf000;
+ //if (data[0]&8) ++result;
// NO serial if using using 0-7 as port expansion (I'm not)
// If you want serial - set the speed in the setup routine, if not, comment out
analogReference(INTERNAL); // 1.1v
+ // get info out of EEPROM
+ EEPROM.get(STRUCTBASE,stored);
// first check if EEPROM info is valid?
- if (EEPROM.read(EEPROM_CHSM)!=0x3b)
- for (a = 0 ; a < EEPROM.length() ; a++) EEPROM.write(a, 0);
- EEPROM.write(EEPROM_CHSM,0x3b);
- EEPROM.write(EEPROM_ID,9); // default I2c address 9
- EEPROM.write(EEPROM_USE_QTECH,1); /// default ON for QTECH
+ EEPROM.put(STRUCTBASE,stored);
- device=EEPROM.read(EEPROM_ID); // programmable address
- Wire.begin(device); // join i2c bus with address #9 by default
+ for (a=0;a<MAXPORTS;a++) ports[a]=0; // all inputs
+ Wire.begin(stored.device); // join i2c bus with address #9 by default
Wire.onReceive(receiveEvent);
Wire.onRequest(requestEvent);
- for (a=0;a<MAXPORTS;a++) ports[a]=0;
for (a=0;a<12;a++){ fade[a][0]=0; fade[a][2]=0; }
for (a=0;a<128;a++) params[a]=0;
+ if (stored.t1!=255) tr1=dallas(stored.t1);
+ if (stored.t2!=255) tr2=dallas(stored.t2);
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
- Wire.write(retparams,2);
+ Wire.write(retparams,3);
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void receiveEvent(int count) {
for (a=0;a<6;a++) params[a]=0;
// Nothing time consuming or visual debugging in here if a RETURN VALUE is expected or the routine to send a byte back could be missed.
while ((tcount--)&&(paramp<128))
uint16_t anback; anback=analogRead(params[1]); retparams[0]=anback>>8; retparams[1]=anback&255;
- EEPROM.update(EEPROM_ID,params[1]);
+ stored.device=params[1]; EEPROM.put(STRUCTBASE,stored);
// update address - will take effect on next powerup of the device as you
// can only call "begin" once
myservos[params[1]].write(params[2]);
- if (ports[params[1]]!=4) { ports[params[1]]=4; pinMode(params[1],OUTPUT); }
+ if (ports[params[1]]!=4) { ports[params[1]]=4; pinMode(params[1],OUTPUT); }
fade[params[1]][0]=1; fade[params[1]][2]=params[2];
if ((params[4]|params[5])==0) tone(params[1],(params[2]<<8)+params[3]); else tone(params[1],(params[2]<<8)+params[3],(params[4]<<8)+params[5]);
case NOTONE: // can't do PWM on pins 3 and 11 while doing TONE...
noTone(params[1]); ports[params[1]]=0;
+ if (params[1]!=stored.t1) { stored.t1=params[1]; EEPROM.put(STRUCTBASE,stored); } // no delay hence first value crap
+ retparams[1]=tr1&255; retparams[0]=tr1>>8;
+ if (params[1]!=stored.t2) { stored.t2=params[1]; EEPROM.put(STRUCTBASE,stored); } // no delay hence first value crap
+ retparams[1]=tr2&255; retparams[0]=tr2>>8;