PICAXE Gaming System

13
© COPLIN 2016-2021 www.kodeklix.com.au Page 8 ® KodeKLIX Overview Download Code/Data Signals Processing Laptop Sensors & Actuators

Transcript of PICAXE Gaming System

Page 1: PICAXE Gaming System

© COPLIN 2016-2021 www.kodeklix.com.au Page 8®

KodeKLIX Overview

Download Code/Data

Signals

Processing

Laptop

Sensors & Actuators

Page 2: PICAXE Gaming System

© COPLIN 2016-2021 www.kodeklix.com.au Page 9®

What is in a KodeKLIX Kit?Kit includes these parts: SnapCPUTM with USB coding cable* Battery box** LEDs Switches Light sensor Speaker Connecting

links and wires

Comprehensive Support: Comprehensive User Manual Structured 7 Chapter Course Over 35 Projects with circuits and code All Code included, web updatable Tutorial information Quizzes and Challenges

* PC connection build-in. USB coding cable supplied.

** Two AA batteries required (not included).

Page 3: PICAXE Gaming System

© COPLIN 2016-2021 www.kodeklix.com.au Page 12®

SnapCPU – adds the ‘brain’

C.1

C.2

C.4

B+

B-

C.3

DL* Link

* Download link connects to your computer to send new code. C.0 flashes during downloading.

C.0 C.1 C.2RED GREEN BLUE

Page 4: PICAXE Gaming System

© COPLIN 2016-2021 www.kodeklix.com.au Page 43®

Project 0.4Variable Resistor (no SnapCPU required)

Assemble the snap components as shown in “Circuit 0.4”

For the LED to light, adjust the dial on the variable resistor [53B]

Try adjusting the dial** clock-wise and anti-clockwise until the LED lights

Investigate the sensitivity of the dial’s position to the brightness of the LED Circuit

0.4

** the dial controls the resistance of the component allowing more or less energy to flow to the LED. The more energy that flows the brighter the LED

Completed

Dial

Page 5: PICAXE Gaming System

© COPLIN 2016-2021 www.kodeklix.com.au Page 44®

Level 0: Quick Quiz What is missing? Complete circuits

Q0.1, Q0.2 and Q0.3 by adding a KLIX part.

There is something wrong incircuit Q0.4; DO NOT build it. What is it that is wrong?

Circuit Q0.3

Circuit Q0.4

Circuit Q0.1

Circuit Q0.2

Page 6: PICAXE Gaming System

© COPLIN 2016-2021 www.kodeklix.com.au Page 67®

Push button input to SnapCPUTM

Assemble the snap components as shown in circuit 2.1; Construct the BLOCKLY code below and download to the SnapCPU

TM

Observe the LED C.0 light up whilst input C.4 is connected to “high” via [14]

Review the following BLOCKLY code to understand what is happening

Project 2.1

Circuit 2.1**code set to read from input C.4

Connecting to “high” is the equivalent of connecting to the +ve terminal of the battery box.

Completed

A push-button switch is momentary (only valid when being pressed) so needs to be held until the code “sees” it.

Challenge: modify the code to make C.0 stay lit for a fixed time after the button C.4 is pressed.

* The SnapCPUTM

connections C.1, C.2, and C.4 are normally “pulled” low, or electrically speaking connected to –ve via a large resistance component; this gives the SnapCPU

TMsome definition

when nothing is connected.

Page 7: PICAXE Gaming System

© COPLIN 2016-2021 www.kodeklix.com.au Page 77®

Input controlling LED Output via the SnapCPUTM

Assemble the snap components as shown in circuit 3.2

Construct the BLOCKLY code below and download to the SnapCPU

TM

Note which colour LED lights up when the input at C.1 is connected to “high”

Spin the GR-LED [09] around; which is colour now lit?

Project 3.2

** LED components are a type of diode, which means that they only light up when current flows in a particular direction. The combo sensor has the two LEDs aligned in opposing directions.

** Input C.1 “high”

** pulse output at C.2 for 1000ms

Completed

Circuit 3.2

Page 8: PICAXE Gaming System

© COPLIN 2016-2021 www.kodeklix.com.au Page 85®

Level 3: Challenges

TRAFFIC WALK LIGHTS

Modify circuit 3.3 and codeto act like a traffic crossing

Add /use a switch to request “I want to cross the road”

Upon request, wait 10seconds then change lights from RED to GREEN for 20seconds, and then back to RED

If you want to be extra tricky

Modify your code to flash REDfor 5seconds before staying RED

Page 9: PICAXE Gaming System

© COPLIN 2016-2021 www.kodeklix.com.au Page 94®

About Binary Numbers…

Binary numbers are how computers count

Humans count in “tens” because we have 10 digits on our hands

Computers count with digits 0 and 1 only

Decimal Binary

0 0 000

1 1 001

2 10 010

3 11 011

4 100 100

5 101 101

6 110 110

7 111 111

Page 10: PICAXE Gaming System

© COPLIN 2016-2021 www.kodeklix.com.au Page 106®

Built in tunes

Assemble the snap components as shown in Circuit 5.7; Construct the BLOCKLY code below and download to the SnapCPU

TM

Press button [C.3] and observe the change in tone

Review the following BLOCKLY code** to understand what is happening

Project 5.7

**Whilst C.3 pressed “on” louder tone plays

Circuit 5.7

Completed

Tune to be played is identified by check/tick mark

Note: Tunes whether built-in of customised are only supported on snap C.2 of the SnapCPU08DX

Tunes only supported on the C.2

Snap.

KodeKLIX®

Plug-in Required

Page 11: PICAXE Gaming System

© COPLIN 2016-2021 www.kodeklix.com.au Page 113®

SFX – Keyboard Synthesizer

Some PICAXE support the TUNE command TUNEs are played in the foreground, so the PICAXE pauses whilst the notes are played

TUNEs can be created from the “keyboard” interface

KodeKLIX® introduces new ways to play TUNEs in the background by translating the routines to EEPROM stored codes Background TUNEs still pause for each note played

Background PWM tunes do not pause for each note played (note: some limitations on tune complexity apply)

Start New TUNE

Note Details

End current TUNE

Pause / Rest Interval

Tempo Setting

Keyboard (octave)

Page 12: PICAXE Gaming System

© COPLIN 2016-2021 www.kodeklix.com.au Page 120®

Analog-to-Digital Concepts

Analog-to-Digital Digital-to-Analog

0-255 is 8-bit Resolution

DigitisingAnalog signals are understood by digital systems only after they have been digitised, Digitising involves measuring the analog signal and storing those values. The scale used to measure determines the accuracy of the digitised version.

Low 2-bit Resolution

Better 3-bit Resolution

0

1

2

3

0

1

2

3

4

5

6

7

BINARY: 1’s and 0’s only; DECIMAL regular 0-9 digits used

Page 13: PICAXE Gaming System

© COPLIN 2016-2021 www.kodeklix.com.au Page 125®

Reading User Adjustable Controls

Assemble the snap components as shown in Circuit 6.4; Construct the BLOCKLY code below and download to the SnapCPU

TM

Set the slide to the middle; adjust the code value until LED C.0 turns “on”

Repeat for each end position of the slide and plot the three data points on a graph

Project 6.4

Circuit 6.4

Challenge: Repeat the above exercise for 10 equally spaced points and plot the value of varA against the distance that the slide has moved. Is the result a line or a curve?

**adjusting the threshold will determine when the action will occur

Completed

**rather than on/off, get a scale value from the light sensor between 0 and 255

Alternate to rotary is slide type

Code is same as Project 6.1