39 lines
908 B
C++
39 lines
908 B
C++
// need 0.1uf cap between vcc and ground for proper operation
|
|
// need 10k pull up resistor on scl and sda for i2c to work correctly
|
|
|
|
// Pin Mappings (Per TinyCore)
|
|
// ATTiny Pin -- Arduino Pin
|
|
// 01 RESET
|
|
// 02 ADC3/PB3
|
|
// 03 ADC2/PB4
|
|
// 04 GND
|
|
// 05 PB0/AIN0/SDA
|
|
// 06 PB1/AIN1
|
|
// 07 PB2/ADC1/SCL
|
|
// 08 VCC
|
|
|
|
// i2c ATTiny Pins
|
|
// sda: 5
|
|
// scl: 7
|
|
|
|
#define I2C_ADDRESS 0x5F
|
|
|
|
#include <Wire.h>
|
|
|
|
void setup() {
|
|
pinMode(6, INPUT);
|
|
|
|
Wire.begin(I2C_ADDRESS);
|
|
Wire.onRequest(requestEvent);
|
|
}
|
|
|
|
void loop() {
|
|
delay(100);
|
|
}
|
|
|
|
// function that executes whenever data is requested by master
|
|
// this function is registered as an event, see setup()
|
|
void requestEvent() {
|
|
Wire.write((uint8_t) analogRead(6)); // Only get 0 - 1023 back so move this into a 1 byte int
|
|
}
|