Stap 2: De Code
//This is the Code for the RaspberryPi: /**************************************************************** * Filename: Attiny_RPi.c (Program for RaspberryPi) * * Send a GPIO signal in both directions from a RaspberryPi * to/from an Attiny85 microcontroller. * * When the button switch attached to the Attiny85 is pressed * it lights the LED attached to the RaspberryPi, and vice-versa. * ****************************************************************/ #include <wiringPi.h> void setup() { wiringPiSetup(); pinMode(2, INPUT); // Switch with pull-down resistor. pinMode(1, INPUT); // Receive signal from Attiny, pull-down resistor. pinMode(14, OUTPUT); // Send signal to Attiny when button pressed. pinMode(11, OUTPUT); // Lights LED when button pressed on Attiny. } void loop() { digitalWrite(14, digitalRead(2)); // Send signal to Attiny if button pressed. digitalWrite(11, digitalRead(1)); // Light LED if signal received from Attiny. } int main() { setup(); for(;;) { loop(); } return(0); }
//And this is the code for the Attiny85: /**************************************************************** * Filename: Attiny_RPi.ino (Program for Attiny85) * * Send a GPIO signal in both directions from a RaspberryPi * to/from an Attiny85 microcontroller. * * When the button switch attached to the Attiny85 is pressed * it lights the LED attached to the RaspberryPi, and vice-versa. * * The Attiny is powered by 3.3 volts from the RaspberryP. * ****************************************************************/ void setup() { pinMode(0, INPUT); // Switch with pull-down reristor. pinMode(4, INPUT); // Receive signal from RPi, pull-down resistor. pinMode(1, OUTPUT); // Send signal to RPi when button pressed. pinMode(3, OUTPUT); // Lights LED when button pressed on RPi. } void loop() { digitalWrite(1, digitalRead(0)); // Send signal to RPi if button pressed. digitalWrite(3, digitalRead(4)); // Light LED if signal received from RPi. }