Created Tue, 12 Nov 2013 18:25:03 +0000 by iyahdub
Tue, 12 Nov 2013 18:25:03 +0000
Ok I just could not resist :lol: , and had to post the Proverbial Led blink Program adapted for the DP32, that has 4 LED's on the board ( Digital Pins 11 to 14). Will scroll them from right to left, speed varying on the variable resistor on board( trim pot). :?:
[color=#007F00]/* Proverbial (4) Led Blink Program[/color] [color=#007F00] [/color] [color=#007F00] Scrolls 4 light emitting diodes(LED), by turning on and off connected to 4 different digital  [/color] [color=#007F00] pins, using the delay() function and the Current millis alike :) . [/color] [color=#007F00] [/color] [color=#007F00] The circuit:[/color] [color=#007F00] * 4 LED's on board - pins D11, D12, D13 and D14 [/color] [color=#007F00] ** Variable resistor/trimpot on A2[/color] [color=#007F00] [/color] [color=#007F00] *** Version done for the chipKit board DP32 **[/color] [color=#007F00] ****  http://dubworks.blogspot.co.uk/[/color] [color=#007F00] */[/color] [color=#007F00]// constants won't change. Used here to [/color] [color=#007F00]// set pin numbers:[/color] const [color=#FF8000]int[/color] ledPin = 11; [color=#007F00]// the number of the LED pin[/color] const [color=#FF8000]int[/color] ledPin1 = 12; const [color=#FF8000]int[/color] ledPin2 = 13; const [color=#FF8000]int[/color] ledPin3 = 14; [color=#FF8000]int[/color] i; [color=#007F00]// Variables will change:[/color] [color=#FF8000]int[/color] ledState = [color=#0066FF]LOW[/color]; [color=#007F00]// ledState used to set the LED[/color] [color=#FF8000]int[/color] ledState1 = [color=#0066FF]LOW[/color]; [color=#FF8000]int[/color] ledState2 = [color=#0066FF]LOW[/color]; [color=#FF8000]int[/color] ledState3 = [color=#0066FF]LOW[/color]; [color=#FF8000]long[/color] previousMillis = 0; [color=#007F00]// will store last time LED was updated[/color] [color=#007F00]// the follow variables is a long because the time, measured in miliseconds,[/color] [color=#007F00]// will quickly become a bigger number than can be stored in an int.[/color] [color=#007F00]//long interval = 500;           // interval at which to blink (milliseconds)[/color] [color=#FF0000]void[/color] [color=#8B308B]setup/color {   [color=#007F00]// set the digital pin as output:[/color]   [color=#FF8000]pinMode[/color](ledPin, [color=#0066FF]OUTPUT[/color]);   [color=#FF8000]pinMode[/color](ledPin1, [color=#0066FF]OUTPUT[/color]);   [color=#FF8000]pinMode[/color](ledPin2, [color=#0066FF]OUTPUT[/color]);   [color=#FF8000]pinMode[/color](ledPin3, [color=#0066FF]OUTPUT[/color]);   [color=#FF8000]pinMode[/color](A2, [color=#0066FF]INPUT[/color]);   ledState = !ledState;  [color=#007F00]//Toggle the bits to start[/color]   ledState1 = !ledState1;   ledState2 = !ledState2;   ledState3 = !ledState3;  } [color=#FF0000]void[/color] [color=#8B308B]loop/color {   [color=#FF8000]boolean[/color] b;   [color=#FF8000]long[/color] interval = [color=#FF8000]analogRead/color; [color=#007F00]// interval at which to enter function.(milliseconds)[/color]   interval= interval/3; [color=#007F00]//So it is not too slow[/color]   [color=#FF8000]digitalWrite[/color](ledPin, ledState);   [color=#FF8000]digitalWrite[/color](ledPin1, ledState1);   [color=#FF8000]digitalWrite[/color](ledPin2, ledState2);   [color=#FF8000]digitalWrite[/color](ledPin3, ledState3);   [color=#007F00]// [/color]   [color=#007F00]// check to see if it's time [/color]   [color=#FF0000]unsigned[/color] [color=#FF8000]long[/color] currentMillis = [color=#FF8000]millis/color;   [color=#FF0000]if[/color](currentMillis - previousMillis > interval) {     [color=#007F00]// save the last time [/color]     previousMillis = currentMillis;       [color=#007F00]// [/color]     [color=#FF8000]int[/color] var;     var=interval-(currentMillis - previousMillis);     [color=#007F00]// conditional depending on increment accumulator[/color]     [color=#FF0000]if/color{       [color=#FF0000]switch[/color] (i) {       [color=#FF0000]case[/color] 0 :
        ledState = !ledState;         [color=#FF8000]digitalWrite[/color](ledPin, ledState);         [color=#FF8000]delay/color;         [color=#FF0000]break[/color];       [color=#FF0000]case[/color] 1 :
        ledState1 = !ledState1;         [color=#FF8000]digitalWrite[/color](ledPin1, ledState1);         [color=#FF8000]delay/color;         [color=#FF0000]break[/color];       [color=#FF0000]case[/color] 2 :
        ledState2 = !ledState2;         [color=#FF8000]digitalWrite[/color](ledPin2, ledState2);         [color=#FF8000]delay/color;         [color=#FF0000]break[/color];       [color=#FF0000]case[/color] 3 :
        ledState3 = !ledState3;         [color=#FF8000]digitalWrite[/color](ledPin3, ledState3);         [color=#FF8000]delay/color;         [color=#FF0000]break[/color];       [color=#FF0000]default[/color]:         b=!b;         [color=#FF0000]break[/color];       }     }     [color=#FF0000]else[/color]{       [color=#FF0000]switch[/color] (i) {       [color=#FF0000]case[/color] 0 :
        ledState = !ledState;         [color=#FF8000]digitalWrite[/color](ledPin, ledState);         [color=#FF8000]delay/color;         [color=#FF0000]break[/color];       [color=#FF0000]case[/color] 1 :
        ledState1 = !ledState1;         [color=#FF8000]digitalWrite[/color](ledPin1, ledState1);         [color=#FF8000]delay/color;         [color=#FF0000]break[/color];       [color=#FF0000]case[/color] 2 :
        ledState2 = !ledState2;         [color=#FF8000]digitalWrite[/color](ledPin2, ledState2);         [color=#FF8000]delay/color;         [color=#FF0000]break[/color];       [color=#FF0000]case[/color] 3 :
        ledState3 = !ledState3;         [color=#FF8000]digitalWrite[/color](ledPin3, ledState3);         [color=#FF8000]delay/color;         [color=#FF0000]break[/color];       [color=#FF0000]default[/color]:         b=!b;         [color=#FF0000]break[/color];       }     }     i++; [color=#007F00]// Increment our accumulator[/color]     i=i%5;     [color=#007F00]// Keep the value within the parameters needed for our switch case[/color]     [color=#007F00]// in this case 5, so we can have 4 + 1 [/color]     [color=#007F00]// (0, 1, 2 and 3) + 1 for default toggling of boolean variable b. (aesthetic reasons ?!) [/color]   } }