Skip to content

Commit 3c791b2

Browse files
committed
Add example directory and webpack config
1 parent 46826be commit 3c791b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1828
-1
lines changed

client.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
'use strict';
22

3+
const _ = require('lodash');
34
const Irken = require('irken');
45

56
const app = new Irken();
67

8+
const examples = _.map(EXAMPLES_LIST, function(name){
9+
return require('./examples/'+name);
10+
});
11+
12+
console.log(examples);
13+
714
const plugins = [
815
{
916
register: require('bs2-serial')

examples/AUX_MAIN_TERM.bs2

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'{$STAMP BS2p}
2+
'{$PBASIC 2.5}
3+
4+
'SOURCE: AUX_MAIN_TERM
5+
'This program demonstrates the use of the AUXIO, MAINIO and IOTERM
6+
'commands to affect I/O pins in the auxiliary and main I/O groups.
7+
8+
Init:
9+
PAUSE 200 'short startup-pause
10+
11+
#SELECT $STAMP 'Notify of module requirements
12+
#CASE BS2, BS2E, BS2SX
13+
#ERROR "Program requires BS2p40"
14+
#CASE BS2P, BS2PE, BS2PX
15+
DEBUG "Note: This program is designed for the BS2p40.", CR
16+
#ENDSELECT
17+
18+
port VAR Bit
19+
20+
Main:
21+
DO
22+
MAINIO 'Switch to main I/O pins
23+
TOGGLE 0 'Toggle state of I/O pin P0
24+
PWM 1, 100, 40 'Generate PWM on I/O pin P1
25+
26+
AUXIO 'Switch to auxiliary I/O pins
27+
TOGGLE 0 'Toggle state of I/O pin X0
28+
PULSOUT 1, 1000 'Generate a pulse on I/O pin X1
29+
PWM 2, 100, 40 'Generate PWM on I/O pin X2
30+
31+
IOTERM port 'Switch to main or aux I/Os
32+
'-- depending on port
33+
TOGGLE 3 'Toggle state of I/O pin 3
34+
'-- on main and aux, alternately
35+
port = ~port 'Invert port
36+
PAUSE 1000 '1 second delay
37+
LOOP

examples/BRANCH.bs2

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'{$STAMP BS2}
2+
'{$PBASIC 2.5}
3+
4+
'SOURCE: BRANCH
5+
'This program shows how the value of an index variable (idx) controls the
6+
'destination of the BRANCH instruction.
7+
8+
idx VAR Byte
9+
10+
Init:
11+
PAUSE 200 'short startup-pause
12+
13+
Main:
14+
DEBUG "idx: ", DEC idx, " "
15+
BRANCH idx, [Task_0, Task_1, Task_2] 'branch to task
16+
DEBUG "BRANCH target error...", CR, CR '... unless out of range
17+
18+
Next_Task:
19+
idx = idx + 1 // 4 'force idx to be 0..3
20+
PAUSE 250
21+
GOTO Main
22+
23+
Task_0:
24+
DEBUG "BRANCHed to Task_0", CR
25+
GOTO Next_Task
26+
27+
Task_1:
28+
DEBUG "BRANCHed to Task_1", CR
29+
GOTO Next_Task
30+
31+
Task_2:
32+
DEBUG "BRANCHed to Task_2", CR
33+
GOTO Next_Task

examples/BUTTON.bs2

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'{$STAMP BS2}
2+
'{$PBASIC 2.5}
3+
4+
'SOURCE: BUTTON
5+
'Connect an active-low circuit (shown in the BUTTON command description) to pin P0
6+
'of the BASIC Stamp. When you press the button, the BUTTON command will detect the
7+
'low signal and then the DEBUG command will execute to display an asterisk (*) on
8+
'the Debug Terminal. After the first button press, then BUTTON command will delay
9+
'approximately one second (200 x 5 ms) before auto-repeating at a rate of
10+
'approximately 100 ms (20 x 5 ms).
11+
12+
Btn PIN 0
13+
btnWrk VAR Byte
14+
15+
Init:
16+
PAUSE 200 'short startup-pause
17+
18+
Main:
19+
'Try changing the Delay parameter (3rd value) in BUTTON to see the effect:
20+
'0 = no delay; 1-254 = varying delays before auto-repeat; 255 = no auto-repeat
21+
'(only one action per button press)
22+
'
23+
'The BUTTON instruction makes the program branch to No_Press unless P0 = 0
24+
25+
PAUSE 5
26+
BUTTON Btn, 0, 200, 20, btnWrk, 0, No_Press
27+
DEBUG "*"
28+
29+
No_Press:
30+
GOTO Main

examples/COUNT.bs2

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'{$STAMP BS2}
2+
'{$PBASIC 2.5}
3+
4+
'SOURCE: COUNT
5+
'Connect an active-low button (shown in the BUTTON command description) to pin P0
6+
'of the BASIC Stamp. The Debug Terminal will prompt you to press the button as
7+
'quickly as possible for a 1-second period. When the count is done, the screen
8+
'will display your "score," the total number of cycles registered by COUNT. Note
9+
'that this score will almost always be greater than the actual number of presses
10+
'because of mechanical switch contact bounce.
11+
12+
PushBtn PIN 0 'Button on P0
13+
14+
Capture CON 1000 '1 second
15+
16+
#SELECT $STAMP 'Set DurAdj according to module type
17+
#CASE BS2, BS2E
18+
DurAdj CON $100 '/ 1
19+
#CASE BS2SX
20+
DurAdj CON $280 '/ 0.400
21+
#CASE BS2P, BS2PX
22+
DurAdj CON $37B '/ 0.287
23+
#CASE BS2PE
24+
DurAdj CON $163 '/ 0.720
25+
#ENDSELECT
26+
27+
cycles VAR Word 'counted cycles
28+
29+
Init:
30+
PAUSE 200 'short startup-pause
31+
32+
Main:
33+
DO
34+
DEBUG CLS, "How many times can you press the button in 1 second?", CR
35+
PAUSE 1000
36+
DEBUG "Ready, set... "
37+
PAUSE 500
38+
DEBUG "GO!", CR
39+
COUNT PushBtn, (Capture */ DurAdj), cycles
40+
DEBUG CR, "Your score: ", DEC cycles, CR
41+
PAUSE 3000
42+
DEBUG "Press button to go again."
43+
DO : LOOP UNTIL (PushBtn = 0) 'wait for button press
44+
LOOP

examples/DATA.bs2

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
'{$STAMP BS2}
2+
'{$PBASIC 2.5}
3+
4+
'SOURCE: DATA
5+
'This program stores a number of large text strings into EEPROM with the DATA
6+
'directive and then sends them, one character at a time via the DEBUG command.
7+
'This is a good demonstration of how to save program space by storing large
8+
'amounts of data in EEPROM directly, rather than embedding the data into separate
9+
'DEBUG commands.
10+
11+
idx VAR Word 'current location number
12+
phrase VAR Nib 'current phrase number
13+
char VAR Byte 'character to print
14+
15+
' ----- Define all text phrases (out of order, just for fun!) -----
16+
'
17+
Text1 DATA "Here is the first part of a large chunk of text "
18+
DATA "data ", CR, "that needs to be transmitted. There's "
19+
DATA "a 5 second delay", CR, "between text paragraphs. ", CR
20+
DATA CR, 0
21+
22+
Text3 DATA "The alternative (having multiple DEBUGs or SEROUTs, "
23+
DATA "each ", CR, "with their own line of text) consumes "
24+
DATA "MUCH more EEPROM ", CR, "(program/data) space. ", CR
25+
DATA CR, 0
26+
27+
Text6 DATA "The 0 at the end of data blocks is used by this program "
28+
DATA "to indicate", CR, "we've reached the End of Text. The Main "
29+
DATA "routine pauses in-between each", CR, "block of text, "
30+
DATA "and then uses a LOOKUP command to retrieve the location", CR
31+
DATA "of the next desired block of text to print. ", 0
32+
33+
Text4 DATA CLS, "This program also demonstrates retrieving data "
34+
DATA "out of order ", CR, "in relation to the way it is "
35+
DATA "stored in EEPROM. Additionally, ", CR, "control codes "
36+
DATA "(like carriage-returns, clear-screens, etc) can ", CR
37+
DATA "be embedded right in the data, as it is here. ", CR
38+
DATA CR, 0
39+
40+
Text2 DATA "This is an example of a good way to save space in "
41+
DATA "your ", CR, "BASIC Stamp's program by storing data "
42+
DATA "into EEPROM and ", CR, "retrieving it, one byte at a "
43+
DATA "time, and transmitting it ", CR, "with just a single "
44+
DATA "DEBUG (or SEROUT) command.", CR, CR, 0
45+
46+
Text5 DATA "The Print_It routine simply takes the idx variable, "
47+
DATA "retrieves ", CR, "the character at the EEPROM location "
48+
DATA "pointed to by it, and ", CR, "prints it to the screen "
49+
DATA "until it finds a byte with a value of 0.", CR, CR, 0
50+
51+
Init:
52+
PAUSE 200 'short startup-pause
53+
54+
Main:
55+
DEBUG CLS 'Clear DEBUG window
56+
FOR phrase = 1 TO 6 'Print blocks one by one
57+
LOOKUP (phrase - 1), [Text1, Text2, Text3, Text4, Text5, Text6], idx
58+
GOSUB Print_It
59+
PAUSE 5000 'Pause for 5 seconds
60+
NEXT
61+
END
62+
63+
Print_It:
64+
DO
65+
READ idx, char 'Get next character
66+
idx = idx + 1 'Point to next location
67+
IF (char = 0) THEN EXIT 'If 0, we're done with block
68+
DEBUG char 'Otherwise, transmit it
69+
LOOP
70+
RETURN 'Return to the main routine

examples/DEBUG_DEBUGIN.bs2

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'{$STAMP BS2}
2+
'{$PBASIC 2.5}
3+
4+
'SOURCE: DEBUG_DEBUGIN
5+
'This program demonstrates the ability to accept user input from the
6+
'Debug Terminal, and to accept numeric entry in any valid format.
7+
8+
myNum VAR Word
9+
10+
Init:
11+
PAUSE 200 'short startup-pause
12+
13+
Main:
14+
DO
15+
DEBUG CLS, "Enter a any number: " 'prompt user
16+
DEBUGIN SNUM myNum 'retrieve number in any format
17+
18+
DEBUG CRSRXY, 0, 2, 'display number in all formats
19+
SDEC ? myNum,
20+
SHEX ? myNum,
21+
SBIN ? myNum
22+
PAUSE 3000
23+
LOOP 'do it again

examples/DO-LOOP.bs2

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'{$STAMP BS2}
2+
'{$PBASIC 2.5}
3+
4+
'SOURCE: DO-LOOP
5+
'This program creates a little guessing game. It starts by creating
6+
'a (psuedo) random number between 1 and 10. The inner loop will run
7+
'until the answer is guessed or 3 tries have been attempted. The
8+
'outer loop has no condition and will cause the inner loop code to
9+
'run until the BASIC Stamp is reprogrammed.
10+
11+
rVal VAR Word 'random value
12+
answer VAR Byte 'game answer
13+
guess VAR Byte 'player guess
14+
tries VAR Nib 'number of tries
15+
16+
Init:
17+
PAUSE 200 'short startup-pause
18+
19+
Main:
20+
DO
21+
RANDOM rVal
22+
answer = rVal.LOWBYTE */ 10 + 1 'create 1 - 10 answer
23+
tries = 0
24+
25+
DO 'get answer until out of tries
26+
DEBUG CLS, "Guess a number (1 - 10). ", CLREOL
27+
DEBUGIN DEC guess 'get new guess
28+
tries = tries + 1 'update tries count
29+
IF (guess <> answer) THEN
30+
DEBUG CR, "Wrong."
31+
PAUSE 500
32+
ENDIF
33+
LOOP UNTIL ((tries = 3) OR (guess = answer))
34+
35+
IF (guess = answer) THEN ' test reason for loop end
36+
DEBUG CR, "You got it!"
37+
ELSE
38+
DEBUG CR, "Sorry ... the answer was ", DEC answer, "."
39+
ENDIF
40+
PAUSE 1000
41+
LOOP ' run again

examples/DTMFOUT.bs2

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'{$STAMP BS2}
2+
'{$PBASIC 2.5}
3+
4+
'SOURCE: DTMFOUT
5+
'This demo program is a rudimentary memory dialer. Since DTMF digits fit
6+
'within a nibble (four bits), the program below packs two DTMF digits into
7+
'each byte of three EEPROM data tables. The end of phone number is marked
8+
'by the nibble $F, since this is not a valid phone-dialing digit.
9+
'Conditional compilation sets the timing adjustment factor so that the
10+
'output will sound the same on any BS2 model.
11+
12+
Spkr PIN 10 'DTMF output on pin 10
13+
14+
#SELECT $STAMP 'Set TmAdj according to module type
15+
#CASE BS2, BS2E, BS2PE
16+
TmAdj CON $100 'x 1.0 (time adjust)
17+
#CASE BS2SX
18+
TmAdj CON $280 'x 2.5
19+
#CASE BS2P
20+
TmAdj CON $3C5 'x 3.77
21+
#CASE BS2PX
22+
TmAdj CON $607 'x 6.03
23+
#ENDSELECT
24+
25+
eeLoc VAR Byte 'EEPROM address of stored number
26+
eeByte VAR Byte 'Byte containing two DTMF digits
27+
dtDig VAR eeByte.NIB1 'Digit to dial
28+
phone VAR Nib 'Pick a phone #
29+
hiLo VAR Bit 'Bit to select upper and lower nib
30+
31+
Parallax DATA $19,$16,$62,$48,$33,$3F 'Phone: 1-916-624-8333
32+
ParallaxFax DATA $19,$16,$62,$48,$00,$3F 'Phone: 1-916-624-8003
33+
Information DATA $15,$20,$55,$51,$21,$2F 'Phone: 1-520-555-1212
34+
35+
Main:
36+
FOR phone = 0 TO 2
37+
'retrieve address
38+
LOOKUP phone, [Parallax, ParallaxFax, Information], eeLoc
39+
GOSUB Dial_Number
40+
PAUSE 2000
41+
NEXT
42+
END
43+
44+
Dial_Number:
45+
DO
46+
READ eeLoc, eeByte 'Retrieve byte from EEPROM
47+
eeLoc = eeLoc + 1 'point to next pair of digits
48+
FOR hiLo = 0 TO 1 'Dial upper and lower digits
49+
IF (dtDig = $F) THEN EXIT 'Hex $F is end-of-number flag
50+
DTMFOUT Spkr, 'dial digit
51+
150 */ TmAdj, 25, [dtDig] '150 ms on, 25 ms off
52+
eeByte = eeByte << 4 'Shift in next digit
53+
NEXT
54+
LOOP UNTIL (dtDig = $F)
55+
RETURN

examples/EXIT.bs2

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'{$STAMP BS2}
2+
'{$PBASIC 2.5}
3+
4+
'SOURCE: EXIT
5+
'This program demonstrates the early termination of DO...LOOP and
6+
'FOR..NEXT loop structures. IF...THEN is used to test a condition,
7+
'and when true, EXIT will terminate the loop.
8+
9+
col VAR Nib
10+
row VAR Nib
11+
12+
Setup:
13+
PAUSE 200 'short startup-pause
14+
col = 0
15+
16+
Main:
17+
DO WHILE (col < 10) 'attempt 10 iterations
18+
FOR row = 0 TO 15 'attempt 16 iterations
19+
IF (row > 9) THEN EXIT 'terminate when row > 9
20+
DEBUG CRSRXY, (col * 8), row, 'print col/row at location
21+
DEC col, "/", DEC row, CR
22+
NEXT
23+
col = col + 1 'update column
24+
IF (col = 3) THEN EXIT 'terminate when col = 3
25+
LOOP
26+
END

0 commit comments

Comments
 (0)