Stap 3: Pulse Width Modulation (PWM) signalen.
U kunt ook PWM-signalen verzenden. Gebruik van hetzelfde programma op de RaspberryPi en zet dit programma op de Attiny85.
/**************************************************************** * Filename: AttinyPWM_RPi.ino (Program for Attiny85) * * The Attiny sends a PWM signal to the RaspberryPi * to vary the brightness of an LED. * * Pressing the button on the RPi lights the LED on the Attiny. * * The Attiny is powered by 3.3 volts from the RaspberryP. * ****************************************************************/ void setup() { pinMode(1, OUTPUT); // Send PWM signal to RPi, has pull-down resistor. pinMode(3, OUTPUT); // Lights LED when button pressed on RPi. pinMode(4, INPUT); // Receive signal from RPi, pull-down resistor. } void loop() { int x=1; for(int i=0;i>-1;i+=x) { analogWrite(1, i); // Send signal to RPi. if(i==128) x=-1; digitalWrite(3, digitalRead(4)); // Light LED if button pressed on RPi. delay(25); } }