MakeCode Signals

Crickit Inputs such as reading analog/signals can sometimes lock up when using MakeCode with CircuitPlayground - we recommend using the alligator connection pads on the 'bare' CPX instead of the Crickit until this is fixed! Or you can use Arduino, CircuitPython, micro:bit, etc.

The Signals block on Crickit allows you to expand your general-purpose inputs and outputs (GPIO).

 

The Circuit Playground Express and Crickit combination is at left.

The Signal pins in MakeCode currently do not have configurable pull up resistors like in CircuitPython or Arduino. Please add external resistors between 3.3V and the signal wire to read things such as buttons where a resistor is needed.

You may want to add buttons, LEDs, switches or simple sensors to your robot project. With Crickit, you get 8 x 'general purpose in/out' (GPIO) pins called signals. Each signal can be a digital input (button/switch), digital output (LED, for example), or analog input.

This lets you add a ton of external components easily, and its all handled by seesaw. Perfect when you have a Feather without analog inputs (like the ESP8266) or just need a ton of extra pins.

The signal pins are on a 3x8 female header, so you can poke wires directly in!

Using Signals in MakeCode

MakeCode has three blocks under the CRICKIT group to help you work with signals:

  • crickit digital read signal allows you to read digital values in 
  • crickit analog read signal reads a signal and provides an analog value from 0-1023
  • crickit digital write signal allows you to write out to a signal line

Analog read returns a number so the block is rounded to place where a number may be used. Digital read is angled so it fits where a decision like if..then..else blocks use. Write signal is a block of its own and will set a signal (Make it HIGH  / 3.3 volts or LOW / 0 volts).

Digital Reads and Writes

Here's an example wiring that goes with the code below.

We have two switch buttons, connected to signals #1 and #2, the other side of the buttons connect to ground

There's also two LEDs, connected to the signals #3 and #4 and the negative wires connected to ground. (All the 3.3V and Ground pins are connected together so you don't have to use the ones right next to the signal pin!)

Note the pull up resistors for the buttons. Seesaw does not allow enabling internal pullup or pulldown resistors at present. Also 330 ohm current limit resistors are shown for the LEDs.

Here is the MakeCode that reads the buttons on signal #1 and #2 and lights signal #3 and signal #4 if the corresponding button is pressed:

Analog Reads

You can also read analog values like from a potentiometer or sensor.

 

Lets do a demonstration where the center tap of a potentiometer is hooked up to Signal #3 - don't forget to also connect one side of the potentiometer to 3.3V and the other side to ground.

And here is the example code. You can see we read the signal with crickit analog read signal which returns a value from 0 to 1023.

For Crickit and Circuit Playground Express

The map MATH function changes 0 to 1023 to 0 to 9. The graph NEOPIXEL block will light the number of NeoPixels map returns in rainbow colors.

Be sure the potentiometer is connected to Crickit Signal 3 and not one of the other Signal terminals.

For Crickit and micro:bit

The code displays a heart icon on the micro:bit display. The brightness is changed by taking the reading from the potentiometer connected to Crickit Signal 3 (0 to 1023) and dividing by 4 to get a brightness from 0 to 255. So the potentiometer is essentially a manual brightness control for the micro:bit LED array.

This guide was first published on May 16, 2018. It was last updated on May 16, 2018. This page (MakeCode Signals) was last updated on Jun 19, 2019.