Back to Activity
Tutorial
Analogue inputs
{% trans 'Sorry, your browser does not support canvas -- please either update your browser or submit your requirements by phone or email.' %}

Accelerometer

Loading Blockly...

Step 1 /7

Introduction

The inputs on CodeBug can be use in two modes, digital and analogue. Digital is on and off like a switch. Analogue gives a value between 0 and 255 depending on the voltage, like a light dimmer-switch.

Step 2 /7

Setting up analogue inputs

  • First click on the blue cog on the start block and tick the checkbox next to leg 0 input/output.

  • Click the cog again to close this window and select analogue input from the leg 0 as dropdown menu.

  • This puts leg 0 into the analogue input mode.

Step 3 /7

Looping

  • Now from the Loops menu, drag in a repeat while true loop and snap it below your start block, so you can repeatedly read and display the value of the analogue leg.

Step 4 /7

Scrolling the value

  • From the Sprite menu, drag in a scroll sprite block and snap it inside your repeat while loop.

  • Also from the Sprite menu, drag in a get string sprite block and snap it to your scroll sprite block.

  • From the Inputs/Outputs menu, drag in a read analogue leg block and snap it to your get string sprite block (on top of the "Hello world" text block).

Step 5 /7

Show leg controls

  • Click the green cog at the top right of the emulator.

  • Tick Show leg controls.

  • Click Apply.

Step 6 /7

Running your code

  • Click the play button on the emulator. It will scroll "255".

  • If you click and hold leg 0, the emulator will start scrolling 0 instead. This shows us the highest and lowest value our analogue leg can read.

Step 7 /7

Download your code

  • Click Download to download your code.

  • Load your code onto your CodeBug.