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

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

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

kohei.okamoto

August 04, 2021
Tweet

More Decks by kohei.okamoto

Other Decks in How-to & DIY

Transcript

  1. 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͸͍ͩͿ͍· ͍ͪস
  2. 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) ; }
  3. 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) ; }
  4. ࣮૷͸͜Μͳײ ͡ 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()͕ແݶʹ܁Γฦ͞Ε Δɻ
  5. ࣮૷͸͜Μͳײ ͡ 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 ; } ΋͏গ͓͠͠ΌΕʹॻ͚Δ ؾ΋͢Δɾɾɾ
  6. Arduinoਪ঑ACΞμϓλ • 9-12V • 250mAҎ্ • DC2.1 ϓϥά (֎ܘ:5.5Φɺ಺ܘ:2.1Φ) •

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