Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic Stamp OEM module By Wilmer Arellano. OEM BASIC Stamp 2sx Wiring diagram Note: - is connection to negative pole of the battery 220 Ohm Push button.

Similar presentations


Presentation on theme: "Basic Stamp OEM module By Wilmer Arellano. OEM BASIC Stamp 2sx Wiring diagram Note: - is connection to negative pole of the battery 220 Ohm Push button."— Presentation transcript:

1 Basic Stamp OEM module By Wilmer Arellano

2 OEM BASIC Stamp 2sx Wiring diagram Note: - is connection to negative pole of the battery 220 Ohm Push button Buzzer LED OUT PIR Motion sensor 9 V battery COM port Microcontroller chip 15 KOhm

3 ' {$STAMP BS2} ' {$PBASIC 2.5} OUTPUT 4 'PIN 4 Declared as output INPUT 0 'PIN 0 Declared as input Green: OUT4=IN0 'PIN 4 will take the value of PIN 0 (switch) PAUSE 1000 GOTO Green Turn ON LED with Switch Input Output Declarations

4 Variables Bit 0 or 1 Nibble (Nib) 0-15 Byte0-255 Word0-65535 or -32768 to + 32767

5 ' {$STAMP BS2} ' {$PBASIC 2.5} NS VAR Bit 'NS is a Bit Variable EW VAR Bit 'EW is a Bit Variable TOTAL VAR Byte 'TOTAL is a Byte Variable NOC CON 20 'NOC is a constant TOTAL = 0 OUTPUT 4 INPUT 1 TOTAL = TOTAL +100 DEBUG ? TOTAL TOTAL= TOTAL/3 DEBUG ? TOTAL DEBUG ? NOC Arithmetic Example

6 Pseudo Code Start of program Measure temperature  Temperature < 100 F? Yes, Turn on heat  Temperature > 102 F? Yes, Turn on cooling fan Go back to start.

7 7 Start Measure Temperature Temp. < 100 Energize Heater Temp. > 102 Energize Fan Star t Yes No Yes No Flowchart

8 8 Sequential Flow Example Pseudo-Code: Start of program  Turn off LED 1  Turn off LED 2  Pause for 2 seconds  Light LED 1  Pause for 2 seconds  Light LED 2  End of program Flowchart: ' {$STAMP BS2} ' {$PBASIC 2.5} LED_OFF CON 0 'LED_OFF is a constant of value 0 LED_ON CON 1 'LED_ON is a constant of value 1 start: OUTPUT 4 OUTPUT 15 OUT4 =LED_OFF OUT15 =LED_OFF PAUSE 1000 OUT4 =LED_ON OUT15 =LED_ON PAUSE 1000 GOTO startCode: Start Turn OFF LED1 Turn OFF LED2 2 Second Pause Turn ON LED1 Turn ON LED2 2 Second Pause End

9 Branching Overview - GOTO Branching is the act of breaking out of a sequence to perform code in another location of the program. The simplest form of branching is to use the GOTO instruction: GOTO label ' {$STAMP BS2} ' {$PBASIC 2.5} OUTPUT 4 'PIN 4 Declared as output INPUT 0 'PIN 0 Declared as input Green: OUT4=IN0 'PIN 4 will take the value of PIN 0 (switch) PAUSE 1000 GOTO Green

10 Conditionals Overview The previous example is an unconditional branch; the program will branch back to Main regardless of any code parameters. In a conditional branch a decision is made based on a current condition to branch or not to branch. As humans, we constantly make decisions based on input as to what to perform. Shower too cold? Turn up the hot. Shower too hot? Turn down the hot water. Microcontrollers can be programmed to act based on conditions

11 IF…THEN The IF-THEN is the primary means of conditional branching. IF condition THEN addressLabel If the condition is evaluated to be true, execution will branch to the named address label. If the condition is not true, execution will continue to the next step in the program sequence. A condition is typically an equality: value1 = value2 value1 > value2 value1 < value2 IN8 = 1

12 12 IF-THEN Example: Alarm  This program will sound the alarm as long as pushbutton 1 is pressed. Start: Is button 1 pressed?Is button 1 pressed? Yes, Go sound AlarmYes, Go sound Alarm No, Go back to startNo, Go back to startAlarm Sound speakerSound speaker Go back to start of programGo back to start of program ' {$STAMP BS2} ' {$PBASIC 2.5} SWITCH VAR Bit start: SWITCH=IN0 IF SWITCH=1 THEN buzz 'IF switch is pressed then turn on buzzer GOTO start buzz: FREQOUT 1, 1000, 5000 GOTO start Pseudo-Code Flowchart Program Code Button 1 Pressed Main Speaker 2000Hz for 1 second Main TrueFalse

13 ' {$STAMP BS2} ' {$PBASIC 2.5} NS VAR Bit EW VAR Bit OUTPUT 4 OUTPUT 10 INPUT 1 Green: OUT4=1 OUT10=0 NS=IN1 IF NS=1 THEN green OUT4=0 OUT10=1 PAUSE 10000 GOTO Green What does this program do?


Download ppt "Basic Stamp OEM module By Wilmer Arellano. OEM BASIC Stamp 2sx Wiring diagram Note: - is connection to negative pole of the battery 220 Ohm Push button."

Similar presentations


Ads by Google