1 / 7

RM2G

RM2G. Let’s use a PUSH-Button!. Now lets use a Push button!. Reading an Input, Controlling an Output

bryony
Download Presentation

RM2G

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. RM2G Let’s use a PUSH-Button!

  2. Now lets use a Push button! • Reading an Input, Controlling an Output The ina register is a read-only register in Cog RAM whose bits store the voltage state of each I/O pin. When an I/O pin is set to output, its ina register bit will report the same value as the outa register bit since ina bits indicate high/low I/O pin voltages with 1 and 0. If the I/O pin is instead an input, its ina register bit updates based on the voltage applied to it. If a voltage above the I/O pin’s 1.65 V logic threshold is applied, the ina register bit stores a 1; otherwise, it stores a 0. The ina register is updated with the voltage states of the I/O pins each time an ina command is issued to read this • register.

  3. So why did we tell you all that? In the next set of code, the pushbutton connected to Pin 8 is going to apply 3.3 volts to Pin 8 when pressed. (0 volts when its not pressed) In the code on the next slide, dira[8] is set to be an input. This is why it is written like this dira[8] := 0. (The zero means INPUT!) So the purpose of this code is to take the push button input and copy that value into the output of P21 (Our RED LED). If the pushbutton state is a 1 (3.3 volts) the LED lights up. If the pushbutton state is a 0 (0 volts) the LED is off! Try it!

  4. ‘File: buttonToLED.spin ‘ LED reflects the state of the Pushbutton PUB ButtonLED dira[21] := 1 ‘make P21 an output dira[8] := 0 ‘make P8 and input repeat ‘endless loop outa[21] := ina[8] ‘copy P8 input to P21 output ‘File: Button_to_ LED.spin Load the program buttonToLED.spin into RAM or EEPROM by selecting F10 or F11.

  5. So what happened? • Did the pushbutton activate the LED? • In what way? CHECK THIS OUT>>> A group of bits can be copied from the ina to outa registers with a command like outa[20..22] := ina[11..8]. The dira[8] := 1 command will also have to be changed to dira[11..8] := %000 before the pushbuttons will make the LEDs light up. Go to the next page

  6. Try these 2 challenges! Save a copy of Button_to_LED.spin, and modify it so that it makes the P8, and P11 pushbuttons light up the P20 and P22 LEDs respectively. Hint: you need only one outa command. Try reversing the order of the pins in outa[20..22]. How does this affect the way the pushbutton inputs map to the LED outputs? What happens if you reverse the order of bits in ina[11..8]?

  7. So what happened? • Were you able to light up several LED’s using the same technique? • What happened when you reversed the order on the LED’s? • What happened when you reversed the order on the Push buttons?

More Related