Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming the CheapBot-14. Start the Editor Set the Mode.

Similar presentations


Presentation on theme: "Programming the CheapBot-14. Start the Editor Set the Mode."— Presentation transcript:

1 Programming the CheapBot-14

2 Start the Editor

3 Set the Mode

4 Set the Serial Port

5 Syntax Check

6 Make your Robot Controller Count Counting: DEBUG B0 = B0 + 1 GOTO Counting Look at B0 in the pop-up Debug window Why does this work?

7 Programs List of statements The statements follow rules Statements are executed one after the other

8 Tokens and Syntax Tokens are elements (words) of the programming language Syntax is the rules for combining tokens

9 A Robot Program Has… Input Output Math Conditional Execution Repetition

10 RAM Variables Numbers that your program creates and updates must be stored in RAM RAM can be updated many times in a program Each RAM variable has a name that acts like the address of the variable

11 Token: RAM Variables Bit (BIT) Byte (B) Word (W)

12 Syntax: RAM Variables BIT0 to BIT31 B0 to 27 W0 to 13 BIT0 = 1 B5 = 215 W2 = 2000

13 RAM Variables

14 Input/Output Pins The CheapBot-14 robot controller has 10 pins that connect it to the world Four control the motors (B.2, B.3, B.4, B.5) Six are for sensors and actuators (C.0, C.1, C.2, C.3, C.4, B.1)

15 Token: HIGH and LOW I/O pins can only be ON or OFF ON means an I/O pin has 5 volts OFF means an I/O pin has 0 volts HIGH turns an I/O pin on (+5V) LOW turns an I/O pin off (ground)

16 Syntax: HIGH and LOW HIGH B.4 LOW B.5

17 HIGH and LOW Notes A HIGH I/O pin is a source A LOW I/O pin is a sink There must be a resistance on an I/O pin before sourcing or sinking current Maximum current is 30 mA

18 Token: Math Numbers exist in RAM variables Math is carried out in RAM variables

19 Syntax: Math Numbers (whole, positive amounts) can be added or subtracted from a value stored in RAM (like B0) Incrementing (adding 1) Decrementing (subtracting 1) B0 = B0 + 1 B2 = B2 - 2

20 Token: IF-THEN Conditional execution (two different ways) If condition is true, then jump execution to a label If condition is true, then execute a block of code

21 Syntax: IF-THEN IF PINB.1 = 1 THEN Turn_Right IF PINC.3 = 0 THEN HIGH B.2 LOW B.3 PAUSE 100 ENDIF

22 Light an LED What command turns on the LED? What command turns it back off?

23 Token: PAUSE The PAUSE command stops the PICAXE from executing anymore commands for a specific length of time.

24 Syntax: PAUSE PAUSE 1000 Units of pause in milliseconds with the maximum being 65,535 ms

25 Blink the LED Use the following commands to blink the LED –Label –PAUSE –HIGH –LOW –GOTO

26 Making an H-Bridge Drive a Motor An H-Bridge makes a motor rotate clockwise, counter-clockwise, or stop based on its two inputs. ClockWise: HIGH B.2 LOW B.3 CounterClockWise: LOW B.2 HIGH B.3 Coast: LOW B.2 LOW B.3 Brake: HIGH B.2 HIGH B.3

27 Token: GOSUB Jump execution to a subroutine Saves program memory Makes it easier to understand a program

28 What is a Subroutine? Subroutines are a simple way to call a series of commands that are used frequently By replacing all the code with calls to subroutines, you make your program smaller

29 Syntax: Subroutines Begins with the name of subroutine (a label) Ends with a command to go back to where it was called (RETURN) Between the label and the RETURN is the code you want to execute in the subroutine Called with the GOSUB command

30 Example of a Subroutine - some code - GOSUB Rotate - rest of code goes here - Rotate: HIGH B.2 LOW B.3 PAUSE 1000 RETURN

31 Token: GOTO Example of code repetition Unconditional

32 Syntax: GOTO CheapBot-14: some code more code GOTO CheapBot-14


Download ppt "Programming the CheapBot-14. Start the Editor Set the Mode."

Similar presentations


Ads by Google