├── README.md ├── TinyMegaI2CMaster.cpp ├── TinyMegaI2CMaster.h ├── examples ├── DigitalClock.ino └── GraphicsLibrary.ino ├── keywords.txt └── library.properties /README.md: -------------------------------------------------------------------------------- 1 | # TinyMegaI2C Library 2 | 3 | This library is now superseded by the TinyI2C library, which incorporates this code and supports all AVR microcontrollers: 4 | 5 | See: https://github.com/technoblogy/tiny-i2c 6 | -------------------------------------------------------------------------------- /TinyMegaI2CMaster.cpp: -------------------------------------------------------------------------------- 1 | /* TinyMegaI2C v1.1.0 2 | 3 | David Johnson-Davies - www.technoblogy.com - 16th February 2022 4 | 5 | CC BY 4.0 6 | Licensed under a Creative Commons Attribution 4.0 International license: 7 | http://creativecommons.org/licenses/by/4.0/ 8 | */ 9 | 10 | #include "TinyMegaI2CMaster.h" 11 | 12 | TinyMegaI2CMaster::TinyMegaI2CMaster() 13 | { 14 | } 15 | 16 | // Minimal Tiny I2C Routines ********************************************** 17 | 18 | void TinyMegaI2CMaster::init () { 19 | pinMode(PIN_WIRE_SDA, INPUT_PULLUP); 20 | pinMode(PIN_WIRE_SCL, INPUT_PULLUP); 21 | uint32_t baud = ((F_CPU/FREQUENCY) - (((F_CPU*T_RISE)/1000)/1000)/1000 - 10)/2; 22 | TWI0.MBAUD = (uint8_t)baud; 23 | TWI0.MCTRLA = TWI_ENABLE_bm; // Enable as master, no interrupts 24 | TWI0.MSTATUS = TWI_BUSSTATE_IDLE_gc; 25 | } 26 | 27 | uint8_t TinyMegaI2CMaster::read (void) { 28 | if (I2Ccount != 0) I2Ccount--; 29 | while (!(TWI0.MSTATUS & TWI_RIF_bm)); // Wait for read interrupt flag 30 | uint8_t data = TWI0.MDATA; 31 | // Check slave sent ACK? 32 | if (I2Ccount != 0) TWI0.MCTRLB = TWI_MCMD_RECVTRANS_gc; // ACK = more bytes to read 33 | else TWI0.MCTRLB = TWI_ACKACT_NACK_gc; // Send NAK 34 | return data; 35 | } 36 | 37 | uint8_t TinyMegaI2CMaster::readLast (void) { 38 | I2Ccount = 0; 39 | return TinyMegaI2CMaster::read(); 40 | } 41 | 42 | bool TinyMegaI2CMaster::write (uint8_t data) { 43 | TWI0.MCTRLB = TWI_MCMD_RECVTRANS_gc; // Prime transaction 44 | TWI0.MDATA = data; // Send data 45 | while (!(TWI0.MSTATUS & TWI_WIF_bm)); // Wait for write to complete 46 | if (TWI0.MSTATUS & (TWI_ARBLOST_bm | TWI_BUSERR_bm)) return false; // Fails if bus error or arblost 47 | return !(TWI0.MSTATUS & TWI_RXACK_bm); // Returns true if slave gave an ACK 48 | } 49 | 50 | // Start transmission by sending address 51 | bool TinyMegaI2CMaster::start (uint8_t address, int readcount) { 52 | bool read; 53 | if (readcount == 0) read = 0; // Write 54 | else { I2Ccount = readcount; read = 1; } // Read 55 | TWI0.MADDR = address<<1 | read; // Send START condition 56 | while (!(TWI0.MSTATUS & (TWI_WIF_bm | TWI_RIF_bm))); // Wait for write or read interrupt flag 57 | if (TWI0.MSTATUS & TWI_ARBLOST_bm) { // Arbitration lost or bus error 58 | while (!(TWI0.MSTATUS & TWI_BUSSTATE_IDLE_gc)); // Wait for bus to return to idle state 59 | return false; 60 | } else if (TWI0.MSTATUS & TWI_RXACK_bm) { // Address not acknowledged by client 61 | TWI0.MCTRLB |= TWI_MCMD_STOP_gc; // Send stop condition 62 | while (!(TWI0.MSTATUS & TWI_BUSSTATE_IDLE_gc)); // Wait for bus to return to idle state 63 | return false; 64 | } 65 | return true; // Return true if slave gave an ACK 66 | } 67 | 68 | bool TinyMegaI2CMaster::restart(uint8_t address, int readcount) { 69 | return TinyMegaI2CMaster::start(address, readcount); 70 | } 71 | 72 | void TinyMegaI2CMaster::stop (void) { 73 | TWI0.MCTRLB |= TWI_MCMD_STOP_gc; // Send STOP 74 | while (!(TWI0.MSTATUS & TWI_BUSSTATE_IDLE_gc)); // Wait for bus to return to idle state 75 | } 76 | 77 | TinyMegaI2CMaster TinyMegaI2C = TinyMegaI2CMaster(); // Instantiate a TinyMegaI2C object 78 | -------------------------------------------------------------------------------- /TinyMegaI2CMaster.h: -------------------------------------------------------------------------------- 1 | /* TinyMegaI2C v1.1.0 2 | 3 | David Johnson-Davies - www.technoblogy.com - 16th February 2022 4 | 5 | CC BY 4.0 6 | Licensed under a Creative Commons Attribution 4.0 International license: 7 | http://creativecommons.org/licenses/by/4.0/ 8 | */ 9 | 10 | #ifndef TinyMegaI2CMaster_h 11 | #define TinyMegaI2CMaster_h 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | // 400kHz clock 19 | uint32_t const FREQUENCY = 400000L; // Hardware I2C clock in Hz 20 | uint32_t const T_RISE = 300L; // Rise time 21 | 22 | // Choose these for 1MHz clock 23 | //uint32_t const FREQUENCY = 1000000L; // Hardware I2C clock in Hz 24 | //uint32_t const T_RISE = 120L; // Rise time 25 | 26 | class TinyMegaI2CMaster { 27 | 28 | public: 29 | TinyMegaI2CMaster(); 30 | void init(void); 31 | uint8_t read(void); 32 | uint8_t readLast(void); 33 | bool write(uint8_t data); 34 | bool start(uint8_t address, int readcount); 35 | bool restart(uint8_t address, int readcount); 36 | void stop(void); 37 | 38 | private: 39 | int I2Ccount; 40 | }; 41 | 42 | extern TinyMegaI2CMaster TinyMegaI2C; 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /examples/DigitalClock.ino: -------------------------------------------------------------------------------- 1 | /* I2C Digital Clock using TinyMegaI2C library 2 | 3 | David Johnson-Davies - www.technoblogy.com - 17th September 2019 4 | 5 | CC BY 4.0 6 | Licensed under a Creative Commons Attribution 4.0 International license: 7 | http://creativecommons.org/licenses/by/4.0/ 8 | */ 9 | 10 | #include 11 | 12 | // Digital clock ********************************************** 13 | 14 | const int RTCAddress = 0x68; 15 | const int DisplayAddress = 0x70; 16 | int Colon = 2; 17 | 18 | char Segment[10] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; 19 | 20 | void SetClock (int hr, int min) { 21 | TinyMegaI2C.start(RTCAddress, 0); 22 | TinyMegaI2C.write(0); 23 | TinyMegaI2C.write(0); 24 | TinyMegaI2C.write(min); 25 | TinyMegaI2C.write(hr); 26 | TinyMegaI2C.stop(); 27 | } 28 | 29 | void InitDisplay () { 30 | TinyMegaI2C.start(DisplayAddress, 0); 31 | TinyMegaI2C.write(0x21); 32 | TinyMegaI2C.restart(DisplayAddress, 0); 33 | TinyMegaI2C.write(0x81); 34 | TinyMegaI2C.restart(DisplayAddress, 0); 35 | TinyMegaI2C.write(0xe1); 36 | TinyMegaI2C.stop(); 37 | } 38 | 39 | void WriteWord (uint8_t b) { 40 | TinyMegaI2C.write(b); 41 | TinyMegaI2C.write(0); 42 | } 43 | 44 | void WriteTime (uint8_t hrs, uint8_t mins) { 45 | TinyMegaI2C.start(DisplayAddress, 0); 46 | TinyMegaI2C.write(0); 47 | WriteWord(Segment[hrs / 16]); 48 | WriteWord(Segment[hrs % 16]); 49 | WriteWord(Colon); 50 | WriteWord(Segment[mins / 16]); 51 | WriteWord(Segment[mins % 16]); 52 | TinyMegaI2C.stop(); 53 | } 54 | 55 | // Setup ********************************************** 56 | 57 | void setup() { 58 | TinyMegaI2C.init(); 59 | InitDisplay(); 60 | SetClock(0x12, 0x34); // Set the time to 12:34 61 | } 62 | 63 | void loop () { 64 | // Read the time from the RTC 65 | TinyMegaI2C.start(RTCAddress, 0); 66 | TinyMegaI2C.write(1); 67 | TinyMegaI2C.restart(RTCAddress, 2); 68 | int mins = TinyMegaI2C.read(); 69 | int hrs = TinyMegaI2C.read(); 70 | TinyMegaI2C.stop(); 71 | 72 | // Write the time to the display 73 | WriteTime(hrs, mins); 74 | 75 | // Flash the colon 76 | Colon = 2 - Colon; 77 | delay(1000); 78 | } 79 | -------------------------------------------------------------------------------- /examples/GraphicsLibrary.ino: -------------------------------------------------------------------------------- 1 | /* Tiny Graphics Library using TinyMegaI2C library 2 | 3 | David Johnson-Davies - www.technoblogy.com - 16th February 2022 4 | 5 | CC BY 4.0 6 | Licensed under a Creative Commons Attribution 4.0 International license: 7 | http://creativecommons.org/licenses/by/4.0/ 8 | */ 9 | 10 | #include 11 | 12 | // OLED display ********************************************** 13 | 14 | // Constants 15 | int const address = 60; 16 | int const commands = 0x00; 17 | int const onecommand = 0x80; 18 | int const data = 0x40; 19 | int const onedata = 0xC0; 20 | 21 | // Character set for text - stored in program memory 22 | const uint8_t CharMap[96][6] PROGMEM = { 23 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 24 | { 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00 }, 25 | { 0x00, 0x07, 0x00, 0x07, 0x00, 0x00 }, 26 | { 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00 }, 27 | { 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00 }, 28 | { 0x23, 0x13, 0x08, 0x64, 0x62, 0x00 }, 29 | { 0x36, 0x49, 0x56, 0x20, 0x50, 0x00 }, 30 | { 0x00, 0x08, 0x07, 0x03, 0x00, 0x00 }, 31 | { 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00 }, 32 | { 0x00, 0x41, 0x22, 0x1C, 0x00, 0x00 }, 33 | { 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x00 }, 34 | { 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00 }, 35 | { 0x00, 0x80, 0x70, 0x30, 0x00, 0x00 }, 36 | { 0x08, 0x08, 0x08, 0x08, 0x08, 0x00 }, 37 | { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, 38 | { 0x20, 0x10, 0x08, 0x04, 0x02, 0x00 }, 39 | { 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00 }, 40 | { 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00 }, 41 | { 0x72, 0x49, 0x49, 0x49, 0x46, 0x00 }, 42 | { 0x21, 0x41, 0x49, 0x4D, 0x33, 0x00 }, 43 | { 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00 }, 44 | { 0x27, 0x45, 0x45, 0x45, 0x39, 0x00 }, 45 | { 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x00 }, 46 | { 0x41, 0x21, 0x11, 0x09, 0x07, 0x00 }, 47 | { 0x36, 0x49, 0x49, 0x49, 0x36, 0x00 }, 48 | { 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00 }, 49 | { 0x00, 0x00, 0x14, 0x00, 0x00, 0x00 }, 50 | { 0x00, 0x40, 0x34, 0x00, 0x00, 0x00 }, 51 | { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, 52 | { 0x14, 0x14, 0x14, 0x14, 0x14, 0x00 }, 53 | { 0x00, 0x41, 0x22, 0x14, 0x08, 0x00 }, 54 | { 0x02, 0x01, 0x59, 0x09, 0x06, 0x00 }, 55 | { 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x00 }, 56 | { 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x00 }, 57 | { 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00 }, 58 | { 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00 }, 59 | { 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00 }, 60 | { 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00 }, 61 | { 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00 }, 62 | { 0x3E, 0x41, 0x41, 0x51, 0x73, 0x00 }, 63 | { 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00 }, 64 | { 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00 }, 65 | { 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00 }, 66 | { 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00 }, 67 | { 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00 }, 68 | { 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x00 }, 69 | { 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00 }, 70 | { 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00 }, 71 | { 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00 }, 72 | { 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00 }, 73 | { 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00 }, 74 | { 0x26, 0x49, 0x49, 0x49, 0x32, 0x00 }, 75 | { 0x03, 0x01, 0x7F, 0x01, 0x03, 0x00 }, 76 | { 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00 }, 77 | { 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00 }, 78 | { 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00 }, 79 | { 0x63, 0x14, 0x08, 0x14, 0x63, 0x00 }, 80 | { 0x03, 0x04, 0x78, 0x04, 0x03, 0x00 }, 81 | { 0x61, 0x59, 0x49, 0x4D, 0x43, 0x00 }, 82 | { 0x00, 0x7F, 0x41, 0x41, 0x41, 0x00 }, 83 | { 0x02, 0x04, 0x08, 0x10, 0x20, 0x00 }, 84 | { 0x00, 0x41, 0x41, 0x41, 0x7F, 0x00 }, 85 | { 0x04, 0x02, 0x01, 0x02, 0x04, 0x00 }, 86 | { 0x40, 0x40, 0x40, 0x40, 0x40, 0x00 }, 87 | { 0x00, 0x03, 0x07, 0x08, 0x00, 0x00 }, 88 | { 0x20, 0x54, 0x54, 0x78, 0x40, 0x00 }, 89 | { 0x7F, 0x28, 0x44, 0x44, 0x38, 0x00 }, 90 | { 0x38, 0x44, 0x44, 0x44, 0x28, 0x00 }, 91 | { 0x38, 0x44, 0x44, 0x28, 0x7F, 0x00 }, 92 | { 0x38, 0x54, 0x54, 0x54, 0x18, 0x00 }, 93 | { 0x00, 0x08, 0x7E, 0x09, 0x02, 0x00 }, 94 | { 0x18, 0xA4, 0xA4, 0x9C, 0x78, 0x00 }, 95 | { 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00 }, 96 | { 0x00, 0x44, 0x7D, 0x40, 0x00, 0x00 }, 97 | { 0x20, 0x40, 0x40, 0x3D, 0x00, 0x00 }, 98 | { 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00 }, 99 | { 0x00, 0x41, 0x7F, 0x40, 0x00, 0x00 }, 100 | { 0x7C, 0x04, 0x78, 0x04, 0x78, 0x00 }, 101 | { 0x7C, 0x08, 0x04, 0x04, 0x78, 0x00 }, 102 | { 0x38, 0x44, 0x44, 0x44, 0x38, 0x00 }, 103 | { 0xFC, 0x18, 0x24, 0x24, 0x18, 0x00 }, 104 | { 0x18, 0x24, 0x24, 0x18, 0xFC, 0x00 }, 105 | { 0x7C, 0x08, 0x04, 0x04, 0x08, 0x00 }, 106 | { 0x48, 0x54, 0x54, 0x54, 0x24, 0x00 }, 107 | { 0x04, 0x04, 0x3F, 0x44, 0x24, 0x00 }, 108 | { 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x00 }, 109 | { 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00 }, 110 | { 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00 }, 111 | { 0x44, 0x28, 0x10, 0x28, 0x44, 0x00 }, 112 | { 0x4C, 0x90, 0x90, 0x90, 0x7C, 0x00 }, 113 | { 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00 }, 114 | { 0x00, 0x08, 0x36, 0x41, 0x00, 0x00 }, 115 | { 0x00, 0x00, 0x77, 0x00, 0x00, 0x00 }, 116 | { 0x00, 0x41, 0x36, 0x08, 0x00, 0x00 }, 117 | { 0x00, 0x06, 0x09, 0x06, 0x00, 0x00 }, // degree symbol = '~' 118 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 } 119 | 120 | }; 121 | 122 | // Current plot position 123 | int x0; 124 | int y0; 125 | 126 | // Write a single command 127 | void Single (uint8_t x) { 128 | TinyMegaI2C.write(onecommand); 129 | TinyMegaI2C.write(x); 130 | } 131 | 132 | void InitDisplay () { 133 | TinyMegaI2C.start(address, 0); 134 | TinyMegaI2C.write(commands); 135 | TinyMegaI2C.write(0xA1); // Flip horizontal 136 | TinyMegaI2C.write(0xAF); // Display on 137 | TinyMegaI2C.stop(); 138 | } 139 | 140 | void ClearDisplay () { 141 | for (int p = 0 ; p < 8; p++) { 142 | TinyMegaI2C.start(address, 0); 143 | Single(0xB0 + p); 144 | TinyMegaI2C.write(data); 145 | for (int q = 0 ; q < 132; q++) TinyMegaI2C.write(0); 146 | TinyMegaI2C.stop(); 147 | } 148 | } 149 | 150 | // Plot point x,y into buffer if in current slice 151 | void PlotPoint (int x, int y) { 152 | TinyMegaI2C.start(address, 0); 153 | Single(0x00 + ((x + 2) & 0x0F)); // Column low nibble 154 | Single(0x10 + ((x + 2)>>4)); // Column high nibble 155 | Single(0xB0 + (y>>3)); // Page 156 | Single(0xE0); // Read modify write 157 | TinyMegaI2C.write(onedata); 158 | TinyMegaI2C.restart(address, 2); 159 | TinyMegaI2C.read(); // Dummy read 160 | int j = TinyMegaI2C.read(); 161 | TinyMegaI2C.restart(address, 0); 162 | TinyMegaI2C.write(onedata); 163 | TinyMegaI2C.write((1<<(y & 0x07)) | j); 164 | Single(0xEE); // Cancel read modify write 165 | TinyMegaI2C.stop(); 166 | } 167 | 168 | // Move current plot position to x,y 169 | void MoveTo (int x, int y) { 170 | x0 = x; 171 | y0 = y; 172 | } 173 | 174 | // Draw a line to x,y 175 | void DrawTo (int x, int y) { 176 | int sx, sy, e2, err; 177 | int dx = abs(x - x0); 178 | int dy = abs(y - y0); 179 | if (x0 < x) sx = 1; else sx = -1; 180 | if (y0 < y) sy = 1; else sy = -1; 181 | err = dx - dy; 182 | for (;;) { 183 | PlotPoint(x0, y0); 184 | if (x0==x && y0==y) return; 185 | e2 = err<<1; 186 | if (e2 > -dy) { err = err - dy; x0 = x0 + sx; } 187 | if (e2 < dx) { err = err + dx; y0 = y0 + sy; } 188 | } 189 | } 190 | 191 | uint8_t ReverseByte (uint8_t x) { 192 | x = (x>>1 & 0x55) | (x<<1 & 0xaa); 193 | x = (x>>2 & 0x33) | (x<<2 & 0xcc); 194 | x = (x>>4 & 0x0f) | (x<<4 & 0xf0); 195 | return x; 196 | } 197 | 198 | // Plot an ASCII character with bottom left corner at x,y 199 | void PlotChar (int c, int x, int y) { 200 | int h = y & 0x07; 201 | for (int p = 0; p < 2; p++) { 202 | TinyMegaI2C.start(address, 0); // Write 203 | Single(0xB0 + (y>>3) + p); // Page 204 | for (int col=0; col<6; col++) { 205 | Single(0x00 + ((x+2+col) & 0x0F)); // Column low nibble 206 | Single(0x10 + ((x+2+col)>>4)); // Column high nibble 207 | Single(0xE0); // Read modify write 208 | TinyMegaI2C.write(onedata); 209 | TinyMegaI2C.restart(address, 2); 210 | TinyMegaI2C.read(); // Dummy read 211 | int j = TinyMegaI2C.read(); 212 | TinyMegaI2C.restart(address, 0); 213 | TinyMegaI2C.write(onedata); 214 | int bits = ReverseByte(pgm_read_byte(&CharMap[c-32][col])); 215 | TinyMegaI2C.write((bits<>(p<<3) | j); 216 | Single(0xEE); // Cancel read modify write 217 | } 218 | TinyMegaI2C.stop(); 219 | } 220 | } 221 | 222 | // Plot text starting at the current plot position 223 | void PlotText(PGM_P s) { 224 | int p = (int)s; 225 | while (1) { 226 | char c = pgm_read_byte(p++); 227 | if (c == 0) return; 228 | PlotChar(c, x0, y0); 229 | x0 = x0 + 6; 230 | } 231 | } 232 | 233 | // Setup ********************************************** 234 | 235 | void setup() { 236 | analogReference(INTERNAL1V1); 237 | TinyMegaI2C.init(); 238 | ClearDisplay(); 239 | InitDisplay(); 240 | } 241 | 242 | const int Now = 1234; // To set the time; eg 12:34 243 | unsigned long StartMins = (unsigned long)((Now/100)*60 + (Now%100)); 244 | 245 | 246 | void loop () { 247 | unsigned int SampleNo = StartMins/15; 248 | // Plot temperature graph 249 | int x1 = 16, y1 = 11; 250 | int yscale = 2; // Points per degree 251 | MoveTo(26, 56); PlotText(PSTR("Temperature ~C")); 252 | // Horizontal axis 253 | MoveTo(x1, y1); DrawTo(x1+96, y1); 254 | for (int i=0; i<=24; i=i+4) { 255 | int mark = x1+i*4; 256 | MoveTo(mark, y1); DrawTo(mark, y1-2); 257 | int tens = i/10; 258 | if (tens != 0) { 259 | PlotChar(tens+'0', mark-6, y1-12); 260 | PlotChar(i%10+'0', mark, y1-12); 261 | } else PlotChar(i%10+'0', mark-3, y1-12); 262 | } 263 | // Vertical axis 264 | MoveTo(x1, y1); DrawTo(x1, y1+50); 265 | for (int i=5; i<=25; i=i+5) { 266 | int mark = y1+i*yscale-10; 267 | MoveTo(x1, mark); DrawTo(x1-2, mark); 268 | int tens = i/10; 269 | if (tens != 0) PlotChar(tens+'0', x1-15, mark-3); 270 | PlotChar(i%10+'0', x1-9, mark-3); 271 | } 272 | for (;;) { 273 | // Now start plotting the temperature every 15 mins 274 | while ((unsigned long) ((StartMins + millis()/60000)/15)%96 == SampleNo); 275 | // Time to take a new reading 276 | SampleNo = (SampleNo+1)%96; 277 | int Temperature = (analogRead(A0)*25)/233; // In half degrees 278 | PlotPoint(SampleNo+x1, Temperature-10+y1); 279 | } 280 | } 281 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | TinyMegaI2C KEYWORD1 2 | init KEYWORD2 3 | read KEYWORD2 4 | readLast KEYWORD2 5 | write KEYWORD2 6 | start KEYWORD2 7 | restart KEYWORD2 8 | stop KEYWORD2 9 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=TinyMegaI2C 2 | version=1.1.0 3 | author=Technoblogy 4 | maintainer=David Johnson-Davies 5 | sentence=Minimal I2C routines for the new 0-series and 1-series ATtiny and ATmega microcontrollers. 6 | paragraph=Minimal I2C routines for the new 0-series and 1-series ATtiny and ATmega microcontrollers. 7 | category=I2C 8 | url=https://github.com/technoblogy/tiny-mega-i2c 9 | architectures=* --------------------------------------------------------------------------------