{{ ───────────────────────────────────────────────── File: ShiftMe_BitBang_Demo.spin Version: 1.0 Copyright (c) 2013 Tymkrs See end of file for terms of use. Author: Whisker ───────────────────────────────────────────────── }} { HISTORY: This object is made as an example for using the ShiftMe ToyMod kit from http://tymkrs.com/ USAGE: • Connect ShiftMe pins Switch Latch, Switch Clock, Switch Serial, LED Latch, LED Clock, and LED Serial to Propeller Pins Switch_Latch_Pin, Switch_Clock_Pin, Switch_Serial_Pin, LED_Latch_Pin, LED_Clock_Pin, and LED_Serial_Pin • Connect ShiftMe pins Vcc and Vss to +3.3v and GND • Use Parallax Serial Terminal to monitor the position of the eight switches } Con _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 'Which Pins is ShiftMe connected to? Switch_Latch_Pin = 0 Switch_Clock_Pin = 1 Switch_Serial_Pin = 2 LED_Latch_Pin = 3 LED_Clock_Pin = 4 LED_Serial_Pin = 5 OBJ pst : "Parallax Serial Terminal" 'As they change, positions of the eight input switches are printed to a Parallax Serial Terminal window on your PC Var long SwitchState[8] 'The positions of the eight switches are stored as 1s and 0s in this array Pub Main | Index 'Set these ShiftMe pins to outputs dira[Switch_Latch_Pin] := 1 dira[Switch_Clock_Pin] := 1 dira[LED_Latch_Pin] := 1 dira[LED_Clock_Pin] := 1 dira[LED_Serial_Pin] := 1 'Set these ShiftMe pins to inputs dira[Switch_Serial_Pin] := 0 'Start Parallax Serial Terminal pst.Start(115_200) 'Wait 1 second for user to enable Parallax Serial Terminal software waitcnt((clkfreq) + cnt) 'Print greeting and initial values to serial terminal pst.str(String("Demonstation is running! Shift Me!")) pst.char(13) 'Set the initial state of the Switch Latch Pin to High outa[Switch_Latch_Pin] := 1 repeat 'Pull the Switch Latch State low then high to store the positions of the 8 switches into 165's register outa[Switch_Latch_Pin] := 0 outa[Switch_Latch_Pin] := 1 'Read the eight switch positions from the 165 shift register into the SwitchState array one at a time repeat Index from 0 to 7 SwitchState[Index] := ina[Switch_Serial_Pin] 'Pull the Switch Clock Pin high then low to read the next register value onto the Switch Serial Pin outa[Switch_Clock_Pin] := 1 outa[Switch_Clock_Pin] := 0 'Print the current states of the 8 switches to Parallax Serial Terminal running on the host PC repeat Index from 0 to 7 pst.dec(SwitchState[Index]) pst.char(32) pst.char(13) 'Write the eight states stored in SwitchState out to the 595 shift register (LEDs) repeat Index from 7 to 0 'Set the state of LED Serial Pin for this LED to the value stored in its slot of the SwitchState array outa[LED_Serial_Pin] := SwitchState[Index] 'Pull the LED Clock Pin high then low to write this LED's state into the 595's register outa[LED_Clock_Pin] := 1 outa[LED_Clock_Pin] := 0 'Pull the LED Latch Pin high then low to apply the contents of the 595's register to the 595's output pins (LEDs) outa[LED_Latch_Pin] := 1 outa[LED_Latch_Pin] := 0 {{ ┌──────────────────────────────────────────────────────────────────────────────────────┐ │ TERMS OF USE: MIT License │ ├──────────────────────────────────────────────────────────────────────────────────────┤ │Permission is hereby granted, free of charge, to any person obtaining a copy of this │ │software and associated documentation files (the "Software"), to deal in the Software │ │without restriction, including without limitation the rights to use, copy, modify, │ │merge, publish, distribute, sublicense, and/or sell copies of the Software, and to │ │permit persons to whom the Software is furnished to do so, subject to the following │ │conditions: │ │ │ │The above copyright notice and this permission notice shall be included in all copies │ │or substantial portions of the Software. │ │ │ │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, │ │INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A │ │PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT │ │HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION │ │OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │ │SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ └──────────────────────────────────────────────────────────────────────────────────────┘ }}