Ropa på påskägget!
Många roar sig under påsken med att gömma respektive leta påskägg. Vi på m pysslade ihop en variant som piper som en kyckling när man ropar på det.
Lägg in nedanstående program i din Circuit Playground, koppla den till ett batteri och placera i påskägget innan det göms. Som en liten bonus blinkar playgrounden glatt i gult och lila när upphittaren öppnar ägget.
Programmet använder sig av ljussensorn och ljudsensorn samt Neopixlarna och högtalaren som alla är inbyggda i Circuit Playground. Du kan enkelt byta vilka färger den blinkar med eller ändra ljudkänsligheten genom att justera inställningarna i programmet. Det är också fritt fram (och ganska roligt) att leka med vilket ljud ägget ska ge ifrån sig.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#include <Adafruit_CircuitPlayground.h> int lightvalue; int soundvalue; void setup() { CircuitPlayground.begin(); } void loop() { soundvalue = CircuitPlayground.soundSensor(); //Lyssna efter ljud if ((soundvalue > 350) or (soundvalue < 300)) { delay(500); CircuitPlayground.playTone(2020, 50); //Pip som en kyckling CircuitPlayground.playTone(2054, 100); delay(50); CircuitPlayground.playTone(2000, 30); CircuitPlayground.playTone(2020, 50); CircuitPlayground.playTone(2054, 300); delay(100); } lightvalue = CircuitPlayground.lightSensor(); //Kolla om det är ljust delay(100); if (lightvalue > 50 ) { delay(250); CircuitPlayground.setPixelColor(0, 128, 0, 128); //Låt Neopixel 0 lysa lila CircuitPlayground.setPixelColor(1, 128, 128, 0); //Låt Neopixel 1 lysa gul CircuitPlayground.setPixelColor(2, 128, 0, 128); CircuitPlayground.setPixelColor(3, 128, 128, 0); CircuitPlayground.setPixelColor(4, 128, 0, 128); CircuitPlayground.setPixelColor(5, 128, 128, 0); CircuitPlayground.setPixelColor(6, 128, 0, 128); CircuitPlayground.setPixelColor(7, 128, 128, 0); CircuitPlayground.setPixelColor(8, 128, 0, 128); CircuitPlayground.setPixelColor(9, 128, 128, 0); delay(500); CircuitPlayground.setPixelColor(0, 128, 128, 0); //Växla färg på Neopixlarna CircuitPlayground.setPixelColor(1, 128, 0, 128); CircuitPlayground.setPixelColor(2, 128, 128, 0); CircuitPlayground.setPixelColor(3, 128, 0, 128); CircuitPlayground.setPixelColor(4, 128, 128, 0); CircuitPlayground.setPixelColor(5, 128, 0, 128); CircuitPlayground.setPixelColor(6, 128, 128, 0); CircuitPlayground.setPixelColor(7, 128, 0, 128); CircuitPlayground.setPixelColor(8, 128, 128, 0); CircuitPlayground.setPixelColor(9, 128, 0, 128); delay(250); CircuitPlayground.clearPixels(); } } |
Glad påsk och mysig äggjakt önskar teamet på m!