Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

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

F5afb4ea805825ee7262ba599edb2d5b?s=128

kohei.okamoto

August 04, 2021
Tweet

Transcript

  1. ϋϜελʔͷճ͠ंͷ૽Ի໰ ୊ʹ௅Μͩ͸ͳ͠ 2021/8/4 Ԭຊᕣฏ

  2. ϋϜͪΌΜ • ϩϘϩϑεΩʔϋϜελʔ˂ • खʹ㕒ͷ͚ͬΔͱख৐Γͯ͘͠Δ ͕טΜͰ͘ΔͷͰ΍Ίͨ • ʹ΅͠͸ݏ͍ • ͻ·ΘΓͷछ͸େ޷͖

  3. γϦίϯεϓϨʔΛͯ͞͠΋ɾɾɾ ճ͠ं͕͏Δ͍͞ʂʂʂ

  4. EventHandler

  5. EventHandler

  6. ҉͘ͳͬͨΒϋϜͪΌΜ ΛরΒ͢Կ͔Λ࡞Γ͍ͨʂ

  7. ϥζύΠͱ͔ͰղܾͰ͖ΔͷͰ͸ʁʁ (Πϝʔδ)

  8. Arduino • ϚΠίϯϘʔυ (OSͱ͔ͳ͍) • ໊લͷ༝དྷ͸ߦ͖͚ͭͷόʔΒ͍͠ • ϥζύΠΑΓ͍҆ • Arduino༻ͷݴޠ/IDEΛ࢖ͬͯ։ൃ͢Δ

  9. CdSηϧ • ེԽΧυϛ΢Ϝ • ޫ͕͋ͨΔͱɺޫిޮՌʹΑΓɺ ఍߅͕௿͘ͳΔ • II-VI଒ͷ૊Έ߹Θͤͷ൒ಋମ

  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) ; }
  14. ͜ΕͰɺ͋ͱ͸ճ࿏Λ૊ΜͰ ࣮૷͢Ε͹OK!!!

  15. ճ࿏͸͜Μͳײ͡

  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 ; } ΋͏গ͓͠͠ΌΕʹॻ͚Δ ؾ΋͢Δɾɾɾ
  18. ͜ΕͰArduinoଆ͸׬੒ʂ Ͱ΋͜Ε͚ͩͩͱύιίϯ͔Β֎͢ͱಈ͔ͳ͍ɾɾɾ

  19. ACΞμϓλ͕ඞཁͳཧ༝ • ύιίϯ͔Βܨ͙ͱɺ5Vͷిѹ͕ڙڅ͞ΕΔɻ • ҰൠՈఉͷిѹ͸100V • ͳͷͰɺͦΕΛม׵͢ΔACΞμϓλ͔Βిݯڙڅ͢Δ͜ͱ͕ඞཁɻ

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

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

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

    • ࠓޙ͸ന৭ͷLEDͳͲʹม͑ͯ࠶௅ઓ༧ఆ
  24. ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ