29
Fifteen Pack from microbit- accessories.co.uk Student notes 1. Theremin.................................................. 2 2. Hearing test.............................................. 3 3. Movement sensor...........................................4 4. Door bell or alarm........................................5 5. Persistence of vision.....................................6 6. Visual Analog Reading.....................................7 7. Touch / Water sensor......................................8 8. LED brightness by PWM.....................................9 9. Inactivity alarm.........................................10 10. Sun Exposure alarm.......................................11 11. Clap on-off.............................................. 12 12. Music notation...........................................13 13. Combination Lock.........................................15 14. Animated Line Graph......................................16 15. Temperature sensor.......................................17

Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Embed Size (px)

Citation preview

Page 1: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Fifteen Pack from microbit-accessories.co.uk

Student notes

1. Theremin.....................................................................................................................2

2. Hearing test.................................................................................................................3

3. Movement sensor........................................................................................................4

4. Door bell or alarm........................................................................................................5

5. Persistence of vision....................................................................................................6

6. Visual Analog Reading.................................................................................................7

7. Touch / Water sensor..................................................................................................8

8. LED brightness by PWM...............................................................................................9

9. Inactivity alarm..........................................................................................................10

10. Sun Exposure alarm...................................................................................................11

11. Clap on-off.................................................................................................................12

12. Music notation...........................................................................................................13

13. Combination Lock......................................................................................................15

14. Animated Line Graph.................................................................................................16

15. Temperature sensor...................................................................................................17

Page 2: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

ThereminBriefYour customer would like to spice up an art exhibit by making it more interactive. They’ve suggested a light controlled sound generator.

Concepts to consider Quick prototyping – this project can be done with just a Forever loop and one line of

blocks.

Think about, plan & make notes on calculations you make

Using variables to document your calculations

Resources

Input Output

or Light sensor Speaker or Headphone adapter

The micro:bit creates the sound using a music block and outputs it from the P0 pin.

You can connect the Light Dependent Resistor light sensor on either pin P1 or P2.

For further connection details, see the accessories handbook.

Project development Is the light sensor digital or analog?

Take the input from the light sensor and use it’s value in the play tone block.

What are the input values from the light sensor?

Using the Power-of-Maths™, how can you extend the range of tones played?

Going further How could you detect that no one is using the exhibit?

Using your detection technique, can you silence the exhibit when it is not in use?

Can you limit the amount of time the unit is in use before it falls silent for a short time?

10th Sept 2016 2 v1.0

This document is copyright free – alter & use as you require

Page 3: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

Hearing testBriefYour form tutor keeps asking if you deaf because you keep getting distracted and appear not to be listening. You would like to check the range of your hearing.

Concepts to consider Code reuse – where have you done something similar before

Think about, plan & make notes on research & calculations you make

Using variables to document your calculations

User interface design

Resources

Input Output

Potentiometer Headphone adapter

The micro:bit creates the sound using a music block and outputs it from the P0 pin.

You can connect the Potentiometer on either pin P1 or P2.

For further connection details, see the accessories handbook.

Project development Is the potentiometer digital or analog?

Take the input from the potentiometer and use it’s value in the play tone block.

What are the input values from the potentiometer?

What frequency range would you expect people of different ages to hear?

What happens to our hearing that means older people cannot hear higher frequency tones?

Using the Power-of-Maths™, how can you extend the range of tones played?

Display the calculated frequency of the tone?

Going further How could you detect that no one is using the exhibit?

Using your detection technique, can you silence the exhibit when it is not in use?

Can you limit the amount of time the unit is in use before it falls silent for a short time?

10th Sept 2016 3 v1.0

This document is copyright free – alter & use as you require

Page 4: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

Movement sensorBriefYour favorite arty client is back again – this time with an exhibit that they want to have make a sound when someone walks by.

Concepts to consider Some input & output devices need special consideration for you to test with them. Some

initial experience to understand them helps, then you can plan to do your testing once you understand what you are getting in to.

Resources

Input Output

or or Passive Infra-Red detector Speaker or Buzzer or Piezo

The micro:bit creates the sound using a music block and outputs it from the P0 pin.

If you are using the buzzer, you can use any pin.

You can connect the PIR detector to any pin

For further connection details, see the accessories handbook.

Project development Is the PIR sensor digital or analog?

Is the PIR output digital or analog?

What setup precautions do you need to make to test this

Going further Rather than a continuous tone, can you make the sound output pulse?

If you store the state of the unit, i.e. whether it has been triggered or not, in a variable, can you get the unit to sound a short pulsing alert when triggered (hint, set the variable) and then wait for the PIR to clear (hint, clear the variable) before it sounds again. Use the variable to decide if you should sound the alert.

10th Sept 2016 4 v1.0

This document is copyright free – alter & use as you require

Page 5: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

Door bell or alarmBriefThe majority of homes have a door bell. Some have alarms. Keeping something safe usually needs an alert or alarm in place, triggered by a switch or other sensor.

Concepts to consider The simplest version doesn’t actually need a micro:bit – what is it that the micro:bit can

do that a simple switch & buzzer circuit can’t?

Resources

Input Output

or or Micro switch Speaker or Buzzer or Piezo

The micro:bit creates the sound using a music block and outputs it from the P0 pin.

If you are using the buzzer, you can use any pin.

For further connection details, see the accessories handbook.

Project development Is the micro switch digital or analog?

What is the simplest script that could be replaced by just wiring the a switch & a buzzer together?

Going further How can you make the output more noticeable?

Can there be two levels of alarm – an initial warning followed after a suitable delay by a full alarm?

Can you use a push switch to act as the door bell whilst the micro switch acts as a door open alarm?

10th Sept 2016 5 v1.0

This document is copyright free – alter & use as you require

Page 6: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

Persistence of visionBriefHow fast can light flashes appear to be on continuously? This is the principal that film & TV works on.

Concepts to consider Some calibration / calculation of the input will be needed to set a flash rate.

We can’t really use the on-board LEDs as they are already flashing – the CPU (main chip) doesn’t have 25 outputs used to drive the 25 LEDs, they are wired in a 5 by 5 matrix that only needs 6 outputs but requires the chip to turn them on & off in sequence very quickly.

Resources

Input Output

Potentiometer LED

You can connect the input & output devices to any of P0, P1 & P2

Red leads go on 3v and black leads go on GND

For further connection details, see the accessories handbook.

Project development Is the potentiometer digital or analog?

Is the LED digital or analog?

Start with a simple script where the potentiometer reading directly sets the pause for the LED on & off times.

Display the pause time when a button is pressed

Create a formula to work out the frequency of flashing from the pause time

Going further Apply your formula and display it along with the pause time

Provide a facility to toggle between continuous and flashing via push button – this can be used to check if someone thinks they can see flashing at a high rate – test them with both flashing and continuous mode several times without telling them what mode you are using.

10th Sept 2016 6 v1.0

This document is copyright free – alter & use as you require

Page 7: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

Visual Analog ReadingBriefMany programming languages have commands that do a lot of work for the programmer. These facilities could easily be written from a blank page but useful building blocks help make software development more efficient.

Concepts to consider You can’t possibly remember the details of every utility command for a programming

language. However it helps enormously to be aware of the different facilities so that you don’t end up ‘re-inventing the wheel’.

Know how to access the help systems for the programming environment

Resources

Input Output

This project uses the micro:bit LED display

Potentiometer

You can connect the potentiometer to any of P0, P1 & P2

Red leads go on 3v and black leads go on GND

For further connection details, see the accessories handbook.

Project development Is the potentiometer digital or analog?

What is the maximum value when using the digital read command?

What is the maximum value when using the analog read command?

Use the plot bar graph block with the analog reading, up to the maximum value for analog readings as a number.

The display has 5 lines or levels – what values are required to display each line?

Display the analog value when a button is pressed – does this match your answer from above

How would you code this functionality if the block didn’t exist.

Going further Use IF to display a message when certain values are reached.

10th Sept 2016 7 v1.0

This document is copyright free – alter & use as you require

Page 8: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

Touch / Water sensorBriefResearch & development is essential in all technical businesses – learning about new products & techniques so you are ready to meet customer requests gives you an edge.

Concepts to consider Store values to capture in a variable so further processing & decisions can be made on a

reliable value.

Calibration for the application is vital – this sensor has one set of values when used for touch and one set of values when used with water.

The sensor can act as a rudimentary level sensor – this needs calibration as well.

Resources

Input Output

This project uses the micro:bit LED display

Water sensor

You can connect the sensor to any of P0, P1 & P2

Red leads go on 3v and black leads go on GND

For further connection details, see the accessories handbook.

Project development Is the water sensor digital or analog?

Use the analog read pin block from Pins to store the reading in a variable

Use an on button pressed block to take a reading & display it so you can calibrate for touch, water sensing & water levels.

Create an initialising variable with your threshold value

Use an IF block to display different things depending on the input – as well as show number and show string, there is show leds.

Going further Wrap your code in a forever loop so it becomes interactive

Use the calibration values for water levels, IF statements & the show leds block to provie a visual representation of the level.

10th Sept 2016 8 v1.0

This document is copyright free – alter & use as you require

Page 9: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

LED brightness by PWMBriefOld style light dimmers & motor speed controllers vary the voltage to vary the brightness or speed. This requires a minimum level of voltage to overcome any resistance or inertia. A more modern technique is to give the device full power but in very short bursts.

Concepts to consider Pulse Width Modulation delivers a regular frequency square wave but with different

widths of the on time to vary the power.

Resources

Input Output

Potentiometer LED

You can connect the potentiometer & the LED to any of P0, P1 & P2 and t

Red leads go on 3v and black leads go on GND

For further connection details, see the accessories handbook.

Project development Use a forever block with a servo set pulse with a analog read pin

Going further Put the potentiometer reading in to a variable and then use that in the servo block.

Use a button pressed block to display the reading.

10th Sept 2016 9 v1.0

This document is copyright free – alter & use as you require

75%25%50%

Page 10: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

Inactivity alarmBriefEvery occupation has its health hazards. Productivity & health issues are a huge problem for sedentary office workers, particularly computer programmers who frequently spend hours focussed on their work. Reminding them to move, hydrate and self-care can be automated.

Concepts to consider Using logic blocks – if either one sensor OR the other can reset the timer.

Resources

Input Output

or or Sound and Passive Infra-Red

detectorsSpeaker or Buzzer or Piezo

Sound output is on P0.

Red leads go on 3v and black leads go on GND

For further connection details, see the accessories handbook.

Project development Create initialisation variables for your alarm interval time

In a forever loop, read the sensors, if either are triggered, update your last sense time, if not, output your alert.

Going further Put the potentiometer reading in to a variable and then use that in the servo block.

Use a button pressed block to display the reading.

10th Sept 2016 10 v1.0

This document is copyright free – alter & use as you require

Page 11: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

Sun Exposure alarmBriefTo keep younger students from being over exposed to the sun, the school would like a sun exposure timer creating that sounds an alert when the amount of time in the sun has passed a safe limit.

Concepts to consider Various settings & calibration will be required – rather than use mysterious numbers in

the program which are often referred to as ‘magic numbers’ – variables should be created to document the configuration

Some thought about unit sizes will be required – the pause is in milliseconds, suitable units should be used for the safe exposure time (seconds, minutes, hours?).

Resources

Input Output

or or LDR Light sensor Speaker or Buzzer or Piezo

The micro:bit creates the sound using a music block and outputs it from the P0 pin.

You can connect the Light Dependent Resistor light sensor on either pin P1 or P2.

For further connection details, see the accessories handbook.

Project development Is the LDR light sensor digital or analog?

You will need a loop to check the light levels and check if the safe time has passed

How will you track time passed? Using a counter or store the start time? How will you accumulate the elapsed time?

Provide a reset option which you will find useful for testing.

Going further How can you make the output more noticeable?

Can there be two levels of alarm – an initial warning that a percentage of time has been reached followed by a full alarm when the limit is reached?

10th Sept 2016 11 v1.0

This document is copyright free – alter & use as you require

Page 12: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

Clap on-offBriefAn older relative used to have a clap on-off light. Every time the gadget hears a loud sound, it changes the state of the output, turning it on if it’s off and vice versa. As a fun Christmas gift, you are going to recreate it for them.

Concepts to consider Storing the state of a program and making changes when something happens (an event)

depending on the state is a common technique.

The state does not just have to be on or off, there could be multiple states – for instance the weather could be Sunny, Clear, Cloudy, Drizzle, Raining or Snowing.

Multiple states can be stored in a program and the states can all interact when making a decision about what changes to make.

Resources

Input Output

Use the micro:bit LEDs orany spare output devices of your choice.

Sound detector

You can connect the sound detector to any pin

The sound level is set by the small screw on the top of the blue potentiometer

For further connection details, see the accessories handbook.

Project development Is the sound sensor digital or analog?

Is the sound output digital or analog?

What setup precautions do you need to make to test this?

Initialise your state variable with an unbound block.

Use an IF block to make decisions based on the detector input and the state variable

Wrap it in a Forever LOOP so it processes all the time

Going further What delay in the forever loop should there be to prevent a longer sound triggering the

device on & off continuously?

Change the code so that a double clap (or sound) is required in a time window to trigger a change – this will add another state (heard first sound) and you will need to store the time you hear the first sound.

10th Sept 2016 12 v1.0

This document is copyright free – alter & use as you require

Page 13: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

Music notationBriefYour art exhibit customer is back with a new piece of work. They would like their new exhibit to play a short tune.

Concepts to consider Many tasks that computers do for us involve it changing one way of representing

information in to another. Data stored as numbers on a disk can be a picture, a video game or a word processing document.

This is encoding. All information is coded. The base, universal code we use is the English language so we don’t think of that as code. But to a native Swahili speaker, English is code that needs to be translated. Semaphore signals, morse code and music notation are all examples of codes.

Resources

Input Output

or Push button Speaker or Headphone adapter

The micro:bit creates the sound using a music block and outputs it from the P0 pin.

You can connect the push button on either pin P1 or P2.

For further connection details, see the accessories handbook.

Project development Is the push button digital or analog?

Look at the piece of music & instructions at the end of this sheet to create a sequence of blocks that play that music.

Going further Find another piece of music to encode – beware of chosing something too complicated.

If the button is not pressed in certain amount of time, can you get the tune to play anyway?

Can you make that delay interval random?

10th Sept 2016 13 v1.0

This document is copyright free – alter & use as you require

Page 14: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

The music – the message

Code a little, test a little.

Enter the first six notes then try it out.

Then enter the rest of the first line of the music plus the first note of the second line.

The last note on the first line is a D in the next octave above, which is not available directly in the Block Editor. You can enter its frequency as a number, which is 587.

The first note on the second line is the octave above, so is a C5.

Notes – the code

With so much technical language in so many subjects, we use acronyms, abbreviations mnemonics to help us. These notes show the ones used in music. The in-between notes spell out the word FACE. The on the line (staves) notes are remembered using the phrase “Every Good Boy Deserves Football”.

Durations4 beats 2 beats 1 beat

½ beat ¼ beat The Block Editor knows about this coding concept for duration, so you can directly enter the number of beats

10th Sept 2016 14 v1.0

This document is copyright free – alter & use as you require

Page 15: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

Combination LockBriefUsing electronic locks with keypads is becoming more common. You must write a program that allows a correctly entered sequence of presses on the A & B buttons to activate an output device.

Concepts to consider This is a multi-step state machine. By storing where in the button press sequence the user

is up to, you can either advance the state if the next button press is correct or reset back to the beginning.

Resources

Input Output

micro:bit A & B buttonsUse the micro:bit LEDs or

any spare output devices of your choice.

Project development Initialise your state variable with an unbound block.

When one of the buttons is pressed, if the current value of the state is expected, then change the state to the next value (usually just the next number). Else, reset back to the beginning.

Some mechanism is needed to check if the state has reached the end of the sequence and perform the unlock / disarm action.

Why this works How many button press sequences are there for 5 presses? How many for 8 presses?

If you provide feedback for correct or incorrect presses, how easy would it be to crack the code?

Going further Add a timer so the sequence has to be completed in a certain time.

Add a lockout timer so that the user has to wait if an incorrect sequence is entered.

Sound an alarm if a certain number of failed attempts are made.

10th Sept 2016 15 v1.0

This document is copyright free – alter & use as you require

Page 16: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

Animated Line GraphBriefYour customer would like a simple moving graph display to be ready as quickly as possible – the micro:bit fits the bill with a display, it just needs some code.

Concepts to consider Trying to code something complicated all in one go is almost always the long route.

Some languages would make this easy, the Block Editor less so, but still entirely doable – you have to use the tools you have to hand.

Resources

Input Output

This project uses the micro:bit LED display

Potentiometer

You can connect the potentiometer to any of P0, P1 & P2

Red leads go on 3v and black leads go on GND

For further connection details, see the accessories handbook.

Project development Capture the value from the potentiometer & scale it for a 0 to 5 value (hint, use division).

Overwrite your input value with a known value so you can test easily. Use a on button pressed block so you can trigger it as you need. Use the simulator

Write a loop that draws just one line of the bar graph (hint, don’t worry about which way it works, left to right, up & down or in reverse, just get it working).

You’ll need a variable for each of the five columns.

Without functions you will have to duplicate your line drawing loop for each column/row.

Cascade the values by copying them in the next one along. Think about which order to do this in.

Put it in a Forever loop, remove the test input value & test

Going further Use a variable for the display speed so it is easy to alter.

Use a second potentiometer to alter the display speed.

10th Sept 2016 16 v1.0

This document is copyright free – alter & use as you require

Page 17: Theremin - Home Page - micro:bit accessoriesmicrobit-accessories.co.uk/.../2016/...notes-v1.0.docx  · Web viewOld style light dimmers & motor speed controllers ... Put the potentiometer

Student notes for the Fifteen Pack from microbit-accessories.co.uk

Temperature sensorBriefYour customer need an accurate digital thermometer in a hurry – the micro:bit has a display, switches and there is a calibrated sensor available.

Concepts to consider Microcontrollers and small devices have simple processors that do not support floating

point maths – so you don’t get any decimal places to work with – only integers.

The instructions for sensors are often useful but need some work to apply.

Much of this task will involve pen & paper time – diving in to coding is a great way to become very confused. When/if you get stuck, start a new sheet of paper – a very literally clean sheet.

Resources

Input Output

This project uses the micro:bit LED display

Temperature

You can connect the sensor to any of P0, P1 & P2, red lead on 3v and black lead on GND

For further connection details, see the accessories handbook.

Sensor & micro:bit details The sensor outputs 10mV per °C. At 25°C it outputs 750mV. At -50°C it outputs 0V.

The micro:bit uses a 3.3V supply so its analog input would read 1023 at 3.3V

Project development Create a formula for the temperature sensor to convert V in to °C

Create a formula for the micro:bit analog input to convert the reading in to V

Do some test / check calculations – what analog reading would 750mV give you. Does this value give you 25°C

You can’t use any decimal places so use multiplication by a power of 10 (10,100, 1000 etc) to get a reading that gives you enough precision.

Code the input to V calc, displaying the reading and the calculated voltage.

Code the formula for the temp sensor, altering it to deal with the extra multiplication that you used above to get a better precision.

Going further Using smaller division by 10 and some subtraction & multiplication, split out the whole

number of the temperature & a couple of decimal places. Display them.

10th Sept 2016 17 v1.0

This document is copyright free – alter & use as you require