{"id":2168,"date":"2022-01-27T23:02:40","date_gmt":"2022-01-28T04:02:40","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/?p=2168"},"modified":"2022-01-28T15:01:06","modified_gmt":"2022-01-28T20:01:06","slug":"interrupts","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/?p=2168","title":{"rendered":"Interrupts"},"content":{"rendered":"<p>Interrupt, Switch Blinking LED from Red to Yellow<\/p>\n<p>Experimented with some of the values.<\/p>\n<p>Tested the button with pin13 before proceeding- button works.<\/p>\n<p>Did not consistently get it to switch colors every time I pressed the button down.<\/p>\n<p>First interrupt attempt (successful), includes questions:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int rLED=9;\r\nint yLED=10;\r\n\r\nint ledOn=5;\r\n\r\nvolatile int switch_color=2;\r\n\r\n\/\/see loop for onoff pattern, did other iterations with more complex onoff patterns, made it more difficult to cue the interrupt\r\nint ledDelay=250;\r\n\r\nvoid setup() {\r\n\r\n  pinMode(rLED,OUTPUT);\r\n  pinMode(yLED,OUTPUT);\r\n\r\n  pinMode(switch_color,INPUT);\r\n  attachInterrupt(digitalPinToInterrupt(switch_color),switchLed,FALLING);\r\n\/\/does rising or falling matter? maybe only needed with more than 2\r\n\r\n  ledOn=rLED;\r\n\r\n  Serial.begin(9600);\r\n\/\/does this impact the switch back to red from yellow?\r\n\r\n}\r\n\r\n\r\nvoid switchLed() {\r\n    ledOn++;\r\n    if (ledOn &gt; yLED) {\r\n        ledOn = rLED;\r\n    }\r\n}\r\n\r\n\r\nvoid loop() {\r\n\/\/red LED turns on and off based on delay variable, then on for delay*10, and off for delay*5 before repeating\r\ndigitalWrite(ledOn,HIGH);\r\ndelay(ledDelay);\r\ndigitalWrite(ledOn, LOW);\r\ndelay(ledDelay);\r\n\r\n\r\n}<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-2170\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/01\/20220127_225521-225x300.jpg\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/01\/20220127_225521-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/01\/20220127_225521-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/01\/20220127_225521-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/01\/20220127_225521-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/01\/20220127_225521-1200x1600.jpg 1200w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/01\/20220127_225521-scaled.jpg 1920w\" sizes=\"(max-width: 225px) 85vw, 225px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Interrupt, Switch Blinking LED from Red to Yellow Experimented with some of the values. Tested the button with pin13 before proceeding- button works. Did not consistently get it to switch colors every time I pressed the button down. First interrupt attempt (successful), includes questions: int rLED=9; int yLED=10; int ledOn=5; volatile int switch_color=2; \/\/see loop &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/?p=2168\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Interrupts&#8221;<\/span><\/a><\/p>\n","protected":false},"author":28,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts\/2168"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2168"}],"version-history":[{"count":5,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts\/2168\/revisions"}],"predecessor-version":[{"id":2174,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts\/2168\/revisions\/2174"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}