' Name : camman_copy_inverted_wakeup.BAS ' Author : Christopher Good ' Notice : Copyright (c) 2006 ' : All Rights Reserved ' Date : 3/2/2006 ' Version : 1.0 ' Notes : Free source code. Compile with Proton IDE Lite (also free). Program your PIC with IC-Prog (also free). ' This version is functionally the same as the Aiptek CamMan, ' but adds an LED on pin 6 as an indicator. Note: LED is optional. ' Wakeup is inverted in this version. ' ' Pin8 = Ground - tie to common, connect to pin 1 via .1MF cap ' Pin7 = GPIO.0 - i/o - not used ' Pin6 = GPIO.1 - i/o - LED - tie pin 6 to high side (anode) of led, tie led low side (cathode) through resistor to ground ' Pin5 = GPIO.2 - i/o - awake - input - used to determine if camera is alive ' Pin4 = GPIO.3 - input only - RC PWM signal - tie to RC signal via 4.7k ohm resistor ' Pin3 = GPIO.4 - i/o - shutter - drive To ground To close shutter - connect To shutter switch ' Pin2 = GPIO.5 - i/o - wakeup - drive to ground to wake up camera - connect to power switch ' Pin1 = Vcc - tie to +5v, connect to pin 8 via .1MF cap Device 12C508 Config INTRC_OSC, MCLRE_OFF, WDT_OFF, CP_OFF ' set config fuses OPTION_REG.5 = 0 ' clock source internal Dim Pulselen As Byte ' Pulselen can be 0 - 255, 100 = 1 ms, 200 = 2 ms Dim Init As Byte ' Init used to flash LED Dim State As Byte ' State can be 0 - 4 Clear ' set all variables = 0 Input GPIO.2 ' set pin 5 to input to monitor awake line Blink: For Init = 1 To 3 ' blink led 3 times High GPIO.1 ' pin 6 - turn led on DelayMS 200 ' wait 0.2 seconds Low GPIO.1 ' pin 6 - turn led off DelayMS 200 ' wait 0.2 seconds Next ReadPWM: Pulselen = PulsIn GPIO.3, High ' pin 4 - read high pulse length, times out after .65535 seconds DelayMS 15 ' delay 15 ms If Pulselen < 50 Then GoTo Blink ' no signal -> blink led again If State = 0 And Pulselen > 75 And Pulselen < 125 Then State = 1 ' state 0 , low pulse -> go to state 1 If State = 1 And Pulselen > 175 And Pulselen < 225 Then State = 2 ' state 1 , high pulse -> go to state 2 If State = 2 And Pulselen > 75 And Pulselen < 125 Then State = 3 ' state 2 , low pulse -> go to state 3 If State = 3 And Pulselen > 175 And Pulselen < 225 Then GoTo takepicture ' state 3 , high pulse -> take a picture If State = 4 And Pulselen > 75 And Pulselen < 125 Then State = 3 ' state 4 , low pulse -> stick has toggled low, go to state 3 GoTo ReadPWM ' restart loop for all other possibilities takepicture: ' take a picture If GPIO.2 = 0 Then GoSub wakeup ' if camera is asleep then wake it up Low GPIO.4 ' pin 3 - drive it low - close the shutter High GPIO.1 ' pin 6 - turn led on DelayMS 250 ' keep shutter closed and LED on for 0.25 seconds Input GPIO.4 ' pin 3 - set to tristate - high impedance Low GPIO.1 ' pin 6 - turn led off State = 4 ' set state as picture taken DelayMS 3000 ' wait 3 seconds for camera to store picture GoTo ReadPWM ' start it all again wakeup: High GPIO.5 ' drive the awake line high to wake camera up DelayMS 500 ' keep is low for .5 second Input GPIO.5 ' tristate the wakeup line - high impedance DelayMS 500 ' delay .5 seconds to allow camera to fully wakeup Return