search
[last updated: 2016-08-03]
-----
//
// Program name: i2CM02
//
// Purpose:
// connect two DigiSparks with i2C
// this unit will be master
//
// Edit History:
// rev. 01: orig from Nick Gammon, but not specific to DS
// so far will not compile...
// rev. 02: incrementally adding code to find why 01 wouldn't compile...
// rev. M02: set up to be master; still adding code; compiles, but non-functional
//
// Program operation/flow:
// reads PB input, sends data to slave
//
// Hardware configuration:
// P0 i2C SDA w/ 4.7k pullup
// P1 onboard LED
// P2 i2C SCL w/ 4.7k pullup
// P3 & 4 semi-reserved for USB programming
// P5 for PB input to ground
// ------------------------
// ************** GLOBALS *******************
#include <TinyWireM.h>
#include "USI_TWI.h"
const byte MasterAddr = 25;
const byte SlaveAddr = 42;
const byte boardLED = 1;
// ---------------- END globals -----------------
// ************** SETUP *******************
void setup() {
// these two lines bombs compiler if uncommented
//TinyWireM.begin (MasterAddr);
// TinyWireM.onReceive (receiveEvent);
pinMode (boardLED, OUTPUT);
}
// -------------- END setup --------------
// ************** LOOP *******************
void loop() {
// put your main code here, to run repeatedly:
}
// --------------- END loop ---------------
// **************** FUNCTION DEFS *****************
void receiveEvent (int howMany) {
while (TinyWireM.available () > 0) {
byte b;
#if BETA_ARDUINO
b = TinyWireM.receive ();
#else
//b = TinyWireM.read ();
#endif
digitalWrite (boardLED, b);
} // end of while available
} // end of receiveEvent
// ----------------------------
// --------------- END function defs ------------
// --------------- END program ------------------
.
.
.
eof