Skip to main content

1.1

Major VersionM

by Pete Prodoehl

Introduction

Connect a 7 Segment Display and a Potentiometer to a Bit Board and control them with code.

We'll explore code to control a 7 Segment Digital Display that can show numbers up to 9999.

Video Overview

  1. We'll connect the 7 Segment Display with a Crazy Circuits Ribbon Cable using all four wires. Start by plugging the connector with the three wires in it (Black, Red, Yellow) into the Pin 1 row of the Bit Board. (Make sure the Black wire is in - and the Yellow wire labeled S1 is closest to the number 1 on the Bit Board.) We can then plug the Orange wire labeled S2 into Pin 0 on the Bit Board. Now we'll connect the other end of the Ribbon Cable to the 7 Segment Display. The pin labels are on the back of the 7 Segment Display PCB. From top to bottom it's CLK, DIO, VCC, GND.
    • We'll connect the 7 Segment Display with a Crazy Circuits Ribbon Cable using all four wires.

    • Start by plugging the connector with the three wires in it (Black, Red, Yellow) into the Pin 1 row of the Bit Board. (Make sure the Black wire is in - and the Yellow wire labeled S1 is closest to the number 1 on the Bit Board.) We can then plug the Orange wire labeled S2 into Pin 0 on the Bit Board.

    • Now we'll connect the other end of the Ribbon Cable to the 7 Segment Display. The pin labels are on the back of the 7 Segment Display PCB. From top to bottom it's CLK, DIO, VCC, GND.

    • CLK stands for Clock and DIO stands for Data Input/Output. VCC is the Positive (+) and GND is the Ground (-) or Negative.

    • S2 (Orange) goes to CLK, S1 (Yellow) goes to DIO, and then + (Positive) goes to VCC and - (Ground or Negative) goes to GND.

    • We'll need to connect one side of the Potentiometer to Ground (GND) and the other side to 3.3v

    • We will then connect the center of the Potentiometer to Pin 0. (Note that Pin 0 is an analog pin, which we'll need for the Potentiometer.)

  2. We used a 3D printed holder we designed to hold the 7 Segment Display in place on the LEGO baseplate.
    • We used a 3D printed holder we designed to hold the 7 Segment Display in place on the LEGO baseplate.

    • You can find the guide for the holder here: 7 Segment Display Holder

    • Alternately you can use some LEGO bricks and a rubber band or tape to hold the display in place.

  3. If you've never used a micro:bit before you'll want to check out this guide:  Bit Board V2 Setup and Use
    • If you've never used a micro:bit before you'll want to check out this guide: Bit Board V2 Setup and Use

    • We're going to load the following code for our 7 Segment Display Potentiometer Map Cheat program: https://makecode.microbit.org/_WpJ6f0X86...

    • In the on start block we'll set up our display using the pins we've connected. CLK to Pin 0 and DIO to Pin 1.

    • We'll also create a variable named potVal to hold the value we read from the analog pin that is connected to the Potentiometer.

    • In the forever block the map function allows us to take the input and map it onto a different scale. This time we'll map 0 to 1023 onto -20 to 120.

    • Finally we'll add the constrain function and the round function. We constrain the value so it's always between 0 and 100, and we round the number to make sure we get an integer and not a floating point (or decimal) value.

    • There are a few different methods of making sure you see the value range you want. This one is fairly simple.

    • It does add a little bit of "dead space" at both ends of the dial, but the tradeoff is that you ensure you can get your lowest value and highest value.

    • Once the code is loaded it should start running immediately but won't display anything until we turn the dial.

    • You can power the micro:bit via the USB cable you used to load the code or you can use a battery pack plugged into the Bit Board.

    • Turn the Potentiometer dial and you should see the number on the 7 Segment Display change.

    • You should be able to see 0 and one of the of the dial and 100 at the other end of the dial.

    • As mentioned, there will be a little bit of space at either end of the dial where you turn it but the number doesn't change, but that's okay because we are either displaying the lowest or highest number we've specified.

  4. Follow along with our recorded Live Stream!
    • Follow along with our recorded Live Stream!

    • (We'll add the video to this step after we do the stream!)

Finish Line

Pete Prodoehl

Member since: 3/4/20

1,940 Reputation

433 Guides authored

0 Comments

Add Comment



View Statistics:

Past 24 Hours: 0

Past 7 Days: 1

Past 30 Days: 31

All Time: 31