kohei.okamoto
August 04, 2021

ハムスターの回し車の騒音問題に挑んだ話/hamster-LT

August 04, 2021

Transcript

10. None
11. Arduinoݴޠ const int LED = 9 ; int val =

0 ; void setup() { pinMode(LED,OUTPUT) ; } void loop() { val = analogRead(0) ; if (val > 500) { digitalWrite(LED, HIGH) ; } else { digitalWrite(LED, LOW) ; } delay(10) ; } • C++Έ͍ͨͳײ͡Ͱॻ͚ ΔΒ͍͠(C++஌Βͳ͍) • Arduino IDE͸͍ͩͿ͍· ͍ͪস
12. const int LED = 9 ; int val = 0

; void setup() { pinMode(LED,OUTPUT) ; } void loop() { val = analogRead(0) ; if (val > 500) { digitalWrite(LED, HIGH) ; } else { digitalWrite(LED, LOW) ; } delay(10) ; }
13. const int LED = 9 ; int val = 0

; void setup() { pinMode(LED,OUTPUT) ; } void loop() { val = analogRead(0) ; if (val > 500) { digitalWrite(LED, HIGH) ; } else { digitalWrite(LED, LOW) ; } delay(10) ; }

16. ࣮૷͸͜Μͳײ ͡ const int LED = 9 ; const int

LIGHT_ON_BUFFER_TIME = 10 ; const int LIGHT_ON_MAX_TIME = 2000 ; boolean isLightOn = false ; boolean lightOnFlag = false ; int secondsDark = 0 ; int secondsLightOn = 0 ; void setup() { pinMode(LED,OUTPUT) ; } void loop() { delay(1000) ; int val = analogRead(0) ; if (val < 500) { roomDark() ; return ; } roomBright() ; } setup()Ͱ࢖͏ϐϯΛએݴ͠ ͨޙʹɺ loop()͕ແݶʹ܁Γฦ͞Ε Δɻ
17. ࣮૷͸͜Μͳײ ͡ void roomDark() { if (lightOnFlag) { // Ұ౓҉͍ؒʹ఺౮ࡁͳΒॲཧΛ͠ͳ͍

return ; } if (isLightOn) { if (secondsLightOn++ > LIGHT_ON_MAX_TIME) { lightOff() ; secondsLightOn = 0 ; lightOnFlag = true ; } } if (secondsDark++ > LIGHT_ON_BUFFER_TIME) { digitalWrite(LED, HIGH) ; isLightOn = true ; secondsDark = 0 ; } } void roomBright() { lightOff() ; isLightOn = false ; lightOnFlag = false ; secondsLightOn = 0 ; secondsDark = 0 ; } ΋͏গ͓͠͠ΌΕʹॻ͚Δ ؾ΋͢Δɾɾɾ

20. Arduinoਪ঑ACΞμϓλ • 9-12V • 250mAҎ্ • DC2.1 ϓϥά (֎ܘ:5.5Φɺ಺ܘ:2.1Φ) •

ηϯλʔϓϥε • ͋Μ·Γ͜͏͍͏෦඼ৄ͘͠ͳ͔ͬͨͷͰ͏͔ͬΓηϯλʔϚΠφ εͷACΞμϓλΛങͬͯ͠·ͬͨɾɾɾΈͳ͞Μ΋͝஫ҙΛɻɻ
21. None

23. ײ૝ • ؆୯ʂʂʂඵͰ࢝ΊΒΕΔʂ • ճ࿏Λ૊Ήͱ͚ͩͪ͜ΐͬͱΉ͍ͣɻ • ఍߅͕͍͘Β͔ಡΉͷ΋׳Εͳ͍ɻ • ͜Μ͘Β͍؆୯ͳ΋ͷͳΒϥζύΠͱ͔͡Όͳ͍͍ͯ͘͢ͶɻͨͿΜ൒ ֹ͘Β͍ɻ΋͏ͪΐ͍Ψνͳ͜ͱ͍ͨ͠ͳΒϥζύΠ͕͍͍ͷ͔΋ɻ

• ࠓޙ͸ന৭ͷLEDͳͲʹม͑ͯ࠶௅ઓ༧ఆ