Alex Glow
Published

SODAQ Mbili Quick Start Guide

Fade an LED by twisting a dial. A minimal Arduino sketch + Seeed Grove modules get you up and running fast.

BeginnerProtip30 minutes1,080
SODAQ Mbili Quick Start Guide

Things used in this project

Story

Read more

Code

PotFader.ino

C/C++
/*
  Brutally kludged together from:
  http://www.arduino.cc/en/Tutorial/AnalogReadSerial
  http://www.arduino.cc/en/Tutorial/Fading
  ...by Alex Glow for Hackster.io
*/

int ledPin = 4;    // LED connected to digital pin 4

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

void loop() {
  int fadeValue = analogRead(0);
  Serial.println(fadeValue);
  fadeValue = map(fadeValue, 0, 1023, 0, 255); // scale potentiometer reading to the LED's brightness range
  analogWrite(ledPin, fadeValue);
  delay(1);  // delay in between reads for stability
}

Credits

Alex Glow
149 projects • 1611 followers
The Hackster team's resident Hardware Nerd. I love robots, music, EEG, wearables, and languages. FIRST Robotics kid.
Contact

Comments

Please log in or sign up to comment.