loading

The next step in usefully using strobing LEDs with the Linkit One board is to get it to respond to limits as the speed of the strobing changes.

This guide will modify the code to allow the board to read the value of a potentiometer and light the on board led at pin D13, which can also be used to on or off a variety of switches

Why would you bother – I hear you think.

  • Use the board to turn on or off lights
  • Modify the code further to include upper limits then build a line following robot
  • Add thermostatic control to a room

There’s other uses – but those come in the next guide

I will not be going over setup of the board or wiring other than to include some images from the previous guide – I will include a link to the guide in the last step of this guide.

The board wiring remains the same as per the last instructable see the resources section at the end

Step 1: Code

Changes in the code

Definition of pin D13 as an OUTPUT – important – use capitals or the board does not recognise the instruction

Inclusion of two if statements at the end to test the pot value for a set value – I have set it to 20. If the pot is less than or equal to 20 the output for d13 is set to high and the led at pin 13 turns on. Conversely if the value is greater than 20 the led turns off.

Copy from here:

byte ledPin[] = {4,5,6,7,8,9,10,11,12};

float ledDelay(65);

int direction=1;

int currentLED = 0;

unsigned long changeTime;

float potPin = A2;

void setup(){

pinMode(13, OUTPUT);

Serial.begin(128000); // opens serial port, sets data rate128000 bps

Serial.println("CLEARDATA"); //clears any residual data

for (int x=0; x<9; x++){

pinMode(ledPin[x], OUTPUT);}

changeTime = millis();

}

void loop(){

ledDelay = analogRead(potPin);

if ((millis()-changeTime)>ledDelay){

changeLED();

changeTime=millis();

}

}

void changeLED(){

for (int x=0; x<9; x++){

digitalWrite(ledPin[x],LOW);

}

digitalWrite(ledPin[currentLED], HIGH);

currentLED += direction;

if (currentLED ==8){direction = -1;}

if (currentLED ==0){direction = 1;}

if (ledDelay <=20) {digitalWrite(13, HIGH);}

if (ledDelay >20) {digitalWrite(13, LOW);}

Serial.print("DATA,TIME,");

Serial.print(currentLED);

Serial.print(",");

Serial.println(ledDelay);

}

Stop Copy here

Step 2: Calibration

To calibrate the 20

limit for the lower light level so that the d13 led lights when it is reached:

  1. upload the code to the board and then open a serial monitor window.
  2. Once the monitor is open cover the Light Dependant resistor as tightly as possible to exclude all light.
  3. Adjust the Pot so that the readings on the serial monitor drop to below 20 on screen.
  4. Note that the D13 led lights up
  5. Remove the cover from the LDR and note that the monitor window value increases and the D13 LDR goes out

About This Instructable

210views

5favorites

License:

Bio: Hi I like to have a go at anything that's interesting, from CNC to toy making, recently I have been dismantling an old Cybot ... More »
More by HUKBMBEAR:Nine Men's Morris Life Hack - repair using a 3D printer LinkIt One - 3d Printed Case 
Add instructable to: