Attiny Projects: Breathing Led
Attiny Projects: Breathing Led
BreathingLED
ThisisanexampleofhowtousetheanalogWritefunctiononanATtinytocontrolthe
brightnessofanLED.ThesketchisaslightlymodifiedversionoftheexampleArduino
FadingsketchthatcanbefoundunderExamples>Analog>Fading.Itcausestheledto
increaseinbrightnessuntilitisallthewayonandthenitdiminishesinbrightness.
Hereisthesketch:
int ledPin = 4; // LED connected to digital pin 9
void setup() {
// nothing happens in setup
}
void loop() {
// fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=2) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=2) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}
LEDControlledbyInfraredSensor
HereisanexampleofusingthebrokenoutsensorontheChipperBoard.Wehave
anIRReceiverDiodeconnectedtothesensorport,5VandGNDontheChipper
Board.WhenevertheIRReceiverDiodesenseIRlight(emittedbyTVremotes)it
sendsasignaltotheATtiny85whichturntheLEDonfor1secondandthenturnsit
off.Hereisthesketch:
int led = 4;
int ir = 3;
int sensor_value = 0;
void setup()
{
pinMode(ir,INPUT);
pinMode(led,OUTPUT);
}
void loop() {
sensor_value = digitalRead(ir);
if (sensor_value == LOW){
digitalWrite(led,HIGH);
delay(1000);
}
else{
digitalWrite(led,LOW);
}
}
BrightBikev2
ThisisanexampleofhowanATtinycanbejustaseffectiveasanArduino.Bright
Bikev1wasaprojectImadeusinga$30ArduinoUnowhichcontrolled16ledsand
oneultrasonicsensor.Thissameprojectcouldhavebeendonewitha$2ATtiny85by
multiplexingandconvertingtheresetpintoanI/Opin.IaddedafewfeaturestoBright
Bikev2soIneededanATtiny84,butyoucanseethedifferenceinqualityandhow
anATtinycanaccomplisheverythingthatanArduinocando.