Create a Super Spy Clock with BASIC Stamp (beginner kit)
cavneb
Posts: 1
I was looking for a simple, yet fun thing I could create with my beginner set. I saw the cricket prank and loved it, but there were not many others I could find. I decided to try to create a clock using only the parts that were provided in the BASIC Stamp (w/ Homework Board) kit. Due to the limited amount of 7-segment LCD displays, I had to get creative on keeping the time. What came of this is the Super Spy Clock!
Here is the code for it:
Post Edited (cavneb) : 9/16/2007 9:48:10 PM GMT
Here is the code for it:
' {$STAMP BS2} ' {$PBASIC 2.5} ' This is my first non-book project with the BASIC Stamp Homeword Board and initial kit. ' I was looking at some watches on Amazon.com and found that their Tokyo brand watches were ' all cryptic and cool. I wanted to see if I could make one with my new BASIC Stamp kit. ' Here is what I came up with. ' Define Variables initial_hour VAR Byte initial_five VAR Byte initial_min VAR Byte counter VAR Byte five_minutes VAR Byte minute_counter VAR Byte hour_marker VAR Byte hours VAR Byte ' Initialize the 7-Segment LED Display OUTH = %00000000 DIRH = %11111111 ' Set Initial Values for variables hours = 1 five_minutes = 0 minute_counter = 0 hour_marker = 0 ' Main Loop DO FOR counter = 0 TO 59 IF (IN0 = 1) THEN GOSUB ADD_MINUTE ENDIF GOSUB DISPLAY_TIME HIGH 11 PAUSE 10 LOW 11 PAUSE 990 NEXT GOSUB ADD_MINUTE LOOP ' Add a minute to the time ADD_MINUTE: IF minute_counter <> 4 THEN minute_counter = minute_counter + 1 ELSE minute_counter = 0 IF five_minutes <> 11 THEN five_minutes = five_minutes + 1 ELSE five_minutes = 0 IF hours <> 6 THEN hours = hours + 1 ELSE hours = 1 IF hour_marker = 0 THEN hour_marker = 1 ELSE hour_marker = 0 ENDIF GOSUB TOGGLE_SIX_HOUR_LED ENDIF ENDIF ENDIF RETURN ' Display the minute LEDs and the 7-Segment Display DISPLAY_TIME: GOSUB DISPLAY_MINUTES GOSUB DISPLAY_HOURS_AND_FIVES RETURN ' This is the part of my code that I am not too happy with. I tried to create a hash of ' minutes and hours with their respective codes, but I couldn't figure out how to convert ' multiple values into a binary string that OUTH accepts. Here's my version (the long one) DISPLAY_HOURS_AND_FIVES: SELECT hours CASE 1 SELECT five_minutes CASE 0 OUTH = %00000001 RETURN CASE 1 OUTH = %00100001 RETURN CASE 2 OUTH = %01000001 RETURN CASE 3 OUTH = %10000001 RETURN CASE 4 OUTH = %00010001 RETURN CASE 5 OUTH = %01100001 RETURN CASE 6 OUTH = %11000001 RETURN CASE 7 OUTH = %10010001 RETURN CASE 8 OUTH = %00110001 RETURN CASE 9 OUTH = %11100001 RETURN CASE 10 OUTH = %11010001 RETURN CASE 11 OUTH = %10110001 RETURN CASE ELSE DEBUG "ERROR" RETURN ENDSELECT CASE 2 SELECT five_minutes CASE 0 OUTH = %00000010 RETURN CASE 1 OUTH = %00100010 RETURN CASE 2 OUTH = %01000010 RETURN CASE 3 OUTH = %10000010 RETURN CASE 4 OUTH = %00010010 RETURN CASE 5 OUTH = %01100010 RETURN CASE 6 OUTH = %11000010 RETURN CASE 7 OUTH = %10010010 RETURN CASE 8 OUTH = %00110010 RETURN CASE 9 OUTH = %11100010 RETURN CASE 10 OUTH = %11010010 RETURN CASE 11 OUTH = %10110010 RETURN CASE ELSE RETURN ENDSELECT CASE 3 SELECT five_minutes CASE 0 OUTH = %00000100 RETURN CASE 1 OUTH = %00100100 RETURN CASE 2 OUTH = %01000100 RETURN CASE 3 OUTH = %10000100 RETURN CASE 4 OUTH = %00010100 RETURN CASE 5 OUTH = %01100100 RETURN CASE 6 OUTH = %11000100 RETURN CASE 7 OUTH = %10010100 RETURN CASE 8 OUTH = %00110100 RETURN CASE 9 OUTH = %11100100 RETURN CASE 10 OUTH = %11010100 RETURN CASE 11 OUTH = %10110100 RETURN CASE ELSE RETURN ENDSELECT CASE 4 SELECT five_minutes CASE 0 OUTH = %00000011 RETURN CASE 1 OUTH = %00100011 RETURN CASE 2 OUTH = %01000011 RETURN CASE 3 OUTH = %10000011 RETURN CASE 4 OUTH = %00010011 RETURN CASE 5 OUTH = %01100011 RETURN CASE 6 OUTH = %11000011 RETURN CASE 7 OUTH = %10010011 RETURN CASE 8 OUTH = %00110011 RETURN CASE 9 OUTH = %11100011 RETURN CASE 10 OUTH = %11010011 RETURN CASE 11 OUTH = %10110011 RETURN CASE ELSE RETURN ENDSELECT CASE 5 SELECT five_minutes CASE 0 OUTH = %00000110 RETURN CASE 1 OUTH = %00100110 RETURN CASE 2 OUTH = %01000110 RETURN CASE 3 OUTH = %10000110 RETURN CASE 4 OUTH = %00010110 RETURN CASE 5 OUTH = %01100110 RETURN CASE 6 OUTH = %11000110 RETURN CASE 7 OUTH = %10010110 RETURN CASE 8 OUTH = %00110110 RETURN CASE 9 OUTH = %11100110 RETURN CASE 10 OUTH = %11010110 RETURN CASE 11 OUTH = %10110110 RETURN CASE ELSE RETURN ENDSELECT CASE 6 SELECT five_minutes CASE 0 OUTH = %00000111 RETURN CASE 1 OUTH = %00100111 RETURN CASE 2 OUTH = %01000111 RETURN CASE 3 OUTH = %10000111 RETURN CASE 4 OUTH = %00010111 RETURN CASE 5 OUTH = %01100111 RETURN CASE 6 OUTH = %11000111 RETURN CASE 7 OUTH = %10010111 RETURN CASE 8 OUTH = %00110111 RETURN CASE 9 OUTH = %11100111 RETURN CASE 10 OUTH = %11010111 RETURN CASE 11 OUTH = %10110111 RETURN CASE ELSE RETURN ENDSELECT CASE ELSE ENDSELECT ' Displays Minute LEDs DISPLAY_MINUTES: GOSUB CLEAR_MINUTES SELECT minute_counter CASE 1 HIGH 2 RETURN CASE 2 HIGH 3 RETURN CASE 3 HIGH 2 HIGH 4 RETURN CASE 4 HIGH 3 HIGH 4 RETURN CASE ELSE ENDSELECT RETURN ' Clears out the minute LEDs CLEAR_MINUTES: LOW 2 LOW 3 LOW 4 RETURN ' This shows whether the hour clock is 1-6 or 7-12. TOGGLE_SIX_HOUR_LED: IF hour_marker = 1 THEN HIGH 5 ELSE LOW 5 ENDIF RETURN
Post Edited (cavneb) : 9/16/2007 9:48:10 PM GMT
Comments
[noparse][[/noparse] "What time is it, cavneb?" ]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support