{{ ───────────────────────────────────────────────── File: TurnMe_Demo_1.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 TurnMe ToyMod kit from http://tymkrs.com/ USAGE: • Connect TurnMe pins A, B and S to Propeller Pins TurnMePinA, TurnMePinB, and TurnMePinS. • Use Parallax Serial Terminal to monitor the value of TurnMeValues 1 and 2 (0-255). } Con _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 'Which Pins are TurnMe connected to? TurnMePinS = 0 'TurnMe Switch TurnMePinB = 1 'TurnMe B TurnMePinA = 2 'TurnMe A OBJ pst : "Parallax Serial Terminal" 'As they change, TurnMeValues 1 and 2 are printed to a Parallax Serial Terminal window on your PC Var long TurnMeDirection 'Which direction did TurnMe rotate byte TurnMeCurrentState 'Current state of the TurnMe A and B pins byte TurnMePreviousState 'Previous state of the TurnMe A and B pins byte TurnMeValue1 'This value is changed by rotating TurnMe while not pressing down its switch byte TurnMeValue2 'This value is changed by rotating TurnMe while pressing down its switch Pub Main 'Set TurnMe pins to inputs dira[TurnMePinS] := 0 dira[TurnMePinA] := 0 dira[TurnMePinB] := 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! Turn Me!")) pst.char(13) pst.dec(TurnMeValue1) pst.char(32) pst.dec(TurnMeValue2) pst.char(13) repeat 'Check which direction TurnMe has turned, if any TurnMeDirection := 0 TurnMeCurrentState := ina[TurnMePinA] TurnMeCurrentState |= (ina[TurnMePinB] << 1) case TurnMePreviousState 1: TurnMeDirection := -(TurnMeCurrentState == 3) - -(TurnMeCurrentState == 0) 2: TurnMeDirection := -(TurnMeCurrentState == 0) - -(TurnMeCurrentState == 3) TurnMePreviousState := TurnMeCurrentState 'Wait 1/100th of a second (debounce) waitcnt((clkfreq / 100) + cnt) 'Check the state of the TurnMe switch if ina[TurnMePinS] == 0 'TurnMe switch is not pressed case TurnMeDirection 1: 'Rotated clockwise with the switch not pressed if TurnMeValue1 == 255 TurnMeValue1 := 0 else TurnMeValue1++ 'Print values to the serial terminal pst.dec(TurnMeValue1) pst.char(32) pst.dec(TurnMeValue2) pst.char(13) -1: 'Rotated counter-clockwise with the switch not pressed if TurnMeValue1 == 0 TurnMeValue1 := 255 else TurnMeValue1-- 'Print values to the serial terminal pst.dec(TurnMeValue1) pst.char(32) pst.dec(TurnMeValue2) pst.char(13) '0: 'No rotation with the switch not pressed else 'TurnMe switch is pressed case TurnMeDirection 1: 'Rotated clockwise with the switch pressed if TurnMeValue2 == 255 TurnMeValue2 := 0 else TurnMeValue2++ 'Print values to the serial terminal pst.dec(TurnMeValue1) pst.char(32) pst.dec(TurnMeValue2) pst.char(13) -1: 'Rotated counter-clockwise with the switch pressed if TurnMeValue2 == 0 TurnMeValue2 := 255 else TurnMeValue2-- 'Print values to the serial terminal pst.dec(TurnMeValue1) pst.char(32) pst.dec(TurnMeValue2) pst.char(13) '0: 'No rotation with the switch pressed {{ ┌──────────────────────────────────────────────────────────────────────────────────────┐ │ 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. │ └──────────────────────────────────────────────────────────────────────────────────────┘ }}