Analog Input

Since the Sino:bit uses the same MCU as the Micro:bit, it has the same analog input capabilities (see the GPIO section).

int analogPin = 0;
int val = 0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  delay(1000);
  val = analogRead(analogPin);
  Serial.println(val);
}

The big LED matrix gives us more potential for displaying things, like a histogram of analog readings.

#include <sinobit.h>

Sinobit matrix = Sinobit();

int analogPin = SINOBIT_PAD_P0;
int readings[12];

void setup()
{
  matrix.begin();
  delay(100);
  matrix.clearScreen();
  for (int i = 0; i < 12; i++) {
    readings[i] = 0;
  }
}

void loop()
{
  delay(1000);

  for (int i = 0; i < 11; i++) {
    readings[i] = readings[i + 1];
  }
  // experience showed that my photocell never got to a max reading
  // which is why I use 12 as the upper limit instead of 11 as expected
  readings[11] = map(analogRead(analogPin), 0, 1023, 0, 12);

  for (int i = 0; i < 12; i++) {
    if (readings[i] == 0) {
      matrix.drawLine(i, 11, i, 0, 0);
    } else if (readings[i] == 11) {
      matrix.drawLine(i, 11, i, 0, 1);
    } else {
      matrix.drawLine(i, 11, i, 12 - readings[i], 1);
      matrix.drawLine(i, 11 - readings[i], i, 0, 0);
    }
  }

  matrix.writeScreen();
}
Last updated on 2017-12-06 at 04.34.34 PM Published on 2017-12-06 at 04.57.43 PM