Created
May 20, 2014 10:56
-
-
Save jgibbard/e1c7c1bf7721f4246832 to your computer and use it in GitHub Desktop.
Bluetooth Controlled LED Frisbee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<project> | |
<gatt in="gatt.xml" /> | |
<hardware in="hardware.xml" /> | |
<script in="frisbee.bgs" /> | |
<image out="BLE112.hex" /> | |
<device type="ble112" /> | |
<boot fw="bootuart" /> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dim currentFrame | |
dim frameTime | |
dim currentSequence(33) | |
dim seqA(17) | |
dim seqB(3) | |
dim seqC(9) | |
dim seqD(3) | |
dim seqE(7) | |
dim seqF(3) | |
dim seqG(5) | |
dim level | |
dim temp | |
procedure change_sequence(newSequence) | |
if newSequence = 1 then | |
memcpy(currentSequence(0), seqA(0), seqA(0:1)+1) | |
end if | |
if newSequence = 2 then | |
memcpy(currentSequence(0), seqB(0), seqB(0:1)+1) | |
end if | |
if newSequence = 3 then | |
memcpy(currentSequence(0), seqC(0), seqC(0:1)+1) | |
end if | |
if newSequence = 4 then | |
memcpy(currentSequence(0), seqD(0), seqD(0:1)+1) | |
end if | |
if newSequence = 5 then | |
memcpy(currentSequence(0), seqE(0), seqE(0:1)+1) | |
end if | |
if newSequence = 6 then | |
memcpy(currentSequence(0), seqF(0), seqF(0:1)+1) | |
end if | |
if newSequence = 7 then | |
memcpy(currentSequence(0), seqG(0), seqG(0:1)+1) | |
end if | |
currentFrame = 1 | |
end | |
event system_boot(major,minor,patch,build,ll_version,protocol,hw) | |
currentFrame = 1 | |
frameTime = 3000 | |
#Sequence 1 - Night rider | |
seqA(0:1) = 16 | |
seqA(1:1) = 1 | |
seqA(2:1) = 2 | |
seqA(3:1) = 4 | |
seqA(4:1) = 8 | |
seqA(5:1) = 16 | |
seqA(6:1) = 32 | |
seqA(7:1) = 64 | |
seqA(8:1) = 128 | |
seqA(9:1) = 128 | |
seqA(10:1) = 64 | |
seqA(11:1) = 32 | |
seqA(12:1) = 16 | |
seqA(13:1) = 8 | |
seqA(14:1) = 4 | |
seqA(15:1) = 2 | |
seqA(16:1) = 1 | |
#Sequence 2 - Flash on and off | |
seqB(0:1) = 2 | |
seqB(1:1) = $FF | |
seqB(2:1) = $00 | |
#Sequence 3 - Circle | |
seqC(0:1) = 8 | |
seqC(1:1) = 1 | |
seqC(2:1) = 2 | |
seqC(3:1) = 4 | |
seqC(4:1) = 8 | |
seqC(5:1) = 16 | |
seqC(6:1) = 32 | |
seqC(7:1) = 64 | |
seqC(8:1) = 128 | |
#Sequence 4 - One colour at a time | |
seqD(0:1) = 2 | |
seqD(1:1) = $55 | |
seqD(2:1) = $AA | |
#Sequence 5 - Dual night rider | |
seqE(0:1) = 6 | |
seqE(1:1) = $18 | |
seqE(2:1) = $24 | |
seqE(3:1) = $42 | |
seqE(4:1) = $81 | |
seqE(5:1) = $42 | |
seqE(6:1) = $24 | |
#Sequence 6 - Half on half off | |
seqF(0:1) = 2 | |
seqF(1:1) = $F0 | |
seqF(2:1) = $0F | |
#Sequence 7 - Mid to end | |
seqG(0:1) = 4 | |
seqG(1:1) = $18 | |
seqG(2:1) = $24 | |
seqG(3:1) = $42 | |
seqG(4:1) = $81 | |
call change_sequence(1) #Set initial sequence | |
#start advertising in connectable mode | |
call gap_set_mode(gap_general_discoverable,gap_undirected_connectable) | |
#Set port 0 to all outputs | |
call hardware_io_port_config_direction(0, $FF) | |
#Enable timer | |
call hardware_set_soft_timer(frameTime,0,0) #32768 = 1 second | |
end | |
event hardware_soft_timer(handle) | |
call hardware_io_port_write(0, $FF, currentSequence(currentFrame)) | |
currentFrame = currentFrame + 1 | |
if currentFrame > currentSequence(0:1) then | |
currentFrame = 1 | |
end if | |
end | |
event connection_disconnected(handle,result) | |
#start advertising again after disconnection | |
call gap_set_mode(gap_general_discoverable,gap_undirected_connectable) | |
end | |
event attributes_value(connection ,reason ,handle ,offset ,value_len, value) | |
level=value(0:1) | |
if level < 100 then | |
call change_sequence(level) | |
else | |
temp = (level - 100) * 327 | |
call hardware_set_soft_timer(temp,0,0) | |
end if | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<configuration> | |
<service uuid="1800"> | |
<description>Generic Access Profile</description> | |
<characteristic uuid="2a00"> | |
<properties read="true" const="true" /> | |
<value>Bluetooth Frisbee</value> | |
</characteristic> | |
<characteristic uuid="2a01"> | |
<properties read="true" const="true" /> | |
<value type="hex">5184</value> | |
</characteristic> | |
</service> | |
<service uuid="a56b2501-df5a-11e3-8b68-0800200c9a66" advertise="true" > | |
<description>Change LED Pattern</description> | |
<characteristic uuid="a56b2500-df5a-11e3-8b68-0800200c9a66"> | |
<properties write_no_response="true" /> | |
<value length="1" /> | |
</characteristic> | |
</service> | |
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<hardware> | |
<sleeposc enable="true" ppm="30" /> | |
<usb enable="false" /> | |
<txpower power="15" bias="5" /> | |
<script enable="true" /> | |
<slow_clock enable="true" /> | |
<pmux regulator_pin="7" /> | |
</hardware> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment