User Tools

Site Tools


oak:tutorials:button

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
oak:tutorials:button [2016/03/20 05:00]
djflix Fixed the non-interrupt example
oak:tutorials:button [2016/03/20 05:13] (current)
djflix
Line 36: Line 36:
   * HIGH (pin is high)   * HIGH (pin is high)
  
-It's important to note that an Interrupt actually interrupts what you'​re ​doing! ​So keep your interrupt ​handlers as simple as possible. Otherwise they might interfere with other time-sensitive operations.+In interrupt will interrupt anything the microcontroller is doing (even if it is in the middle of a function!) but will return after executing the interrupt ​handlerSee some example of a good and a bad handleButtonPress() interrupt handler: 
 + 
 +<​code>​ 
 +bool event_has_happened = false; 
 + 
 +void good_handleButtonPress() { 
 +  //set a bool to true so we can handle it in loop() 
 +  event_has_happened = true;  
 +
 + 
 +void bad_handleButtonPress() { 
 +  // wait user to release button 
 +  delay(500);  
 +  //Handle the button press now so we won't forget it happened! 
 +  call_another_slow_function();​  
 +
 +</​code>​ 
  
 =====Circuit:​===== =====Circuit:​=====
Line 45: Line 62:
  
 **2. LED** **2. LED**
-After adding the resistors, you can add the LED. When connecting the LED, double-check the polarity. The shorter leg is the cathode (-) and the longer leg is the anode (+). Connect the **cathode** to the top (10K) resistor, and connect the **anode** to P2 of the Oak using a wire (the blue wire in the example).+After adding the resistors, you can add the LED. When connecting the LED, double-check the polarity. The shorter leg is the cathode (-) and the longer leg is the anode (+). Connect the **cathode** to the top (150 Ohm) resistor, and connect the **anode** to P2 of the Oak using a wire (the blue wire in the example).
  
 **3. Button** **3. Button**
oak/tutorials/button.1458475259.txt.gz · Last modified: 2016/03/20 05:00 by djflix