Music Box Software Assignment 3: A GUI part 1

Download Report

Transcript Music Box Software Assignment 3: A GUI part 1

Computer Engineering
Activities
Interfacing
Music Box Project
ACSE 2004
Graham Smyth
Computer Engineering Units
Grade 10/11/12
1. Hardware
2. Networking
3. Integrated Circuits
4. Programming
5. Interfaces
Interfacing Activities
Grade 10
• One bit
• Three LEDs
• LED simulators
• ASCII
• Binary counting
• Light patterns
• Intersections
• AC ???
Grade 11
• One bit
• One byte
• DC motor
• Bi-directional
• LED traffic light
• LED intersection
• Demultiplexer
• GUIs
• Mouse control
• AC ??
Interfacing Activities
Grade 12
• One byte
• LED intersection
• Stop Lights AC?
• Vehicles
• Security systems
• Drag strips
• Music Box
• Latches
• Marquees
• GUIs/Mouse Control
Introduction to Traffic Lights
Traffic Lights
Traffic Lights
Introduction to Motors
Motors
Introduction to Music
Music Box
Note indicator Light
Note push button
Music: Pipe Organ
Breadboard Connections
Connected
High
Fives
Divider
Low
Fives
Connected
Music Box Software
Turing
• parallelput(number) - reads 8 pins
• put parallelget
- reads 5 pins
• mousewhere(x,y,click)
• play(“CDEFG”)
• drawline(x1,y1,x2,y2,red)
• FREE!!!
Interfacing System
Unit 5
Computer
• Parallelport
Wires
Interface
• Wires
• ICs
• Resistors
• Capacitors
• Transistors
Peripheral
• LED's
• Motors
• Lights
• Robots
• Music Box
•Joysticks
Wires
Music Box Hardware
• Five male pins
• One D sub connector
• Cable 1 – D sub to Breadboard
• Four N.O. pushbuttons
• Four Resistors (Brown/Black/Orange)
• One Breadboard
• Extra wire
• Enhancement hardware ????
Music Box Hardware - Resistor
(Four Required)
1
0 X 103
Brown Black Orange Gold
Tolerance
+-5%
Resistor Chart
BLACK
BROWN
RED
ORANGE
YELLOW
GREEN
BLUE
VIOLET
GRAY
WHITE
BAND 1
0
1
2
3
4
5
6
7
8
9
BAND 2
0
1
2
3
4
5
6
7
8
9
BAND 3
1
10
100
1 000
10 000
100 000
1 000 000
10 000 000
100 000 000
1 000 000 000
Music Box Hardware
Cable: D sub to Breadboard
Insulated Wire
Male Pin
Small Crimp Tab
Stripped Wire
Large Crimp Tab
3 Pair Cable
White/Green
Green/ White
Orange/ White
White/Orange
Blue/ White
White/ Blue
Cable with Male Pins
Music Box Hardware:
Normally Open Switch
Schematic
Physical
1
1
2
2
Inputting Data
Music Box Hardware :
Parallelport
Input
I0 – I3
13
12
11
10
25 24 23
9
22
8
21
7
20 19
6
5
18
4
17
3
16
2
15
1
Output
D0 – D7
14
Grounds
18 - 25
Input I4
View from back of Computer
D Sub Connector /Harness
D Sub Connector Colour Code
Pin # Colour
2
White/ Green
10
Green/ White
11
Orange/ White
12
White/ Orange
13
Blue/ White
18
White/ Blue
D Sub Connector
D sub
Connector
Pin 10
Pin 2
Pin 18
D Sub Connector
Pin 2
Check
Bottom, 2 Down
D Sub Connector
Check
Pin 2, Bottom, 2 Down
Pin 18, Top, 5 Down
Pin 10, Bottom, 10 Down
Pin 11
Pin 12
Pin 13
Total of six wires from D sub connector
Breadboard
Switches Span Divider
Breadboard with Resistors
Resistors to Top Rail
Align
Brown/Black/Orange
D Sub to Breadboard Cable
To Pin 2
White/Green
Four Wires
To Pin18
White/Blue
Switch to
Ground
D Sub to Breadboard Cable
Pin 10
Green/ White
Pin 2
White/Green
Pin18
White/Blue
Pin 11
Orange/ White
Pin 12
White/Orange
Pin 13
Blue/ White
The hardware is complete.
Now to the software
Music Box Software
Assignment 1
Write a program that will continuously scan
for input values from the MUSIC BOX.
Music Box Software
Assignment 1
parallelput(1)
loop
put parallelget
end loop
% Start of infinite loop.
% Returns input pin values.
% End of loop.
Music Box Note Matrix
Switch
Note
1
2
3
C
D
E
4
G
Parallelget Value
Remember these Numbers
Music Box Software
Assignment 2
Write a program that will play the notes
“CDEG” each as quarter notes.
Music Box Software
Assignment 2
parallelput(1)
var value : int
loop
value := parallelget
if value = ______ then
play (“C”)
elsif value = _____ then
play (“D”)
Etc
Save as MusicBox2
Music Box Software
Assignment 3
Write a program that will play the notes “CDEG” each
as quarter notes and at the same time display a GUI
representing the played notes.
Adding Graphics Screen
(640,400)
(0,0)
Music Box Software
Assignment 3: A GUI part 1
locatexy (300, 300)
put "MUSIC BOX PLAYER"
locatexy (200, 140)
put "C
D
E
G"
% drawing 4 circles with perimeter black
drawoval (200, 200, 40, 40, black)
drawoval (300, 200, 40, 40, black)
drawoval (400, 200, 40, 40, black)
drawoval (500, 200, 40, 40, black)
Music Box Software
Assignment 3: A GUI part 2
% filling 4 circles with white
drawfilloval (200, 200, 40, 40, white, black)
drawfilloval (300, 200, 40, 40, white, black)
drawfilloval (400, 200, 40, 40, white, black)
drawfilloval (500, 200, 40, 40, white, black)
Music Box Software
Assignment 3: A GUI part 3
parallelput(1)
var value : int
loop
value := parallelget
if value = ______ then
% fills “C” GUI with red
drawfilloval (200, 200, 40, 40, red, black)
% plays C for a quarter note
play “C”
% sets “C” GUI back to white
drawfilloval (200, 200, 40, 40, white, black)
Music Box Software
Assignment 3: A GUI part 4
elsif value = _____ then
% fills “D” GUI with red
drawfilloval (300, 200, 40, 40, red, black)
play “D”
% sets “D” GUI back to white
drawfilloval (300, 200, 40, 40, white, black)
Similarly for notes E and G
Save as MusicBox3
Music Box Tune
Mary Had a Little
Mary had a little lamb
E D C D E E E rest
Little lamb
D D D rest
Little lamb
E G G rest
Mary had a little lamb
E D C DEE
E rest
Whose fleece was white as snow
E
D
D
E
D C
Save as MusicBox4
Music Theory





play (“8CDEFGAB>C”) – plays one octave of 8th
notes from middle C
play(“<BAGFEDC”) – plays scale in reverse in 8th
notes if it follows previous line
play (“>4CDEFGAB”) – plays one octave of
quarter notes one octave up from middle C
play (">6CpC+pC-") – plays one octave up from
middle C, a C 16th note, a rest, C sharp, a rest,
and a C flat
play(“1C2C4C6C”) – plays whole, half, quarter,
and 16th C note
Music Box Software
Assignment 4
Write a program that will:
• play a tune
• display a GUI of the notes being played
• change the colour of the note name.
Save as MusicBox5
Music Box Software
Assignment 5
Write a program that will automatically
play “Mary Had a Little Lamb”.
Save as MusicBox6
Additional Music Box
Software
Additions
• Add an LED above each key on the keyboard
• Add additional keys to the keyboard
• Store a tune
• Test a users ability to replay the tune
More Hands-On Activities
• Keyboard
• Intersection
• Robot
• World’s Largest Joystick
Addresses
[email protected]
www.classictechnology.ca
www.holtsoft.com