Tuesday, 19 April 2016
Test programing
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Pin 3 has an LED connected on most Arduino boards.
// give it a name: TEST 1
int led = 3;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
/* **********************************************************
TEST 2
***********************************************************
/*
Fade
This example shows how to fade an LED on pin 3
using the analogWrite() function.
This example code is in the public domain.
*/
int led = 3; // the pin that the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 3 to be an output:
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 3:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
/* **********************************************************
TEST 3
***********************************************************
/*
14core LED Chase Effect with 14Core Stater Kit
*/
byte ledPin[] = {3, 5, 6, 9, 10}; // Define the pins on arduino
int ledDelay(10); // delay changes
int leddirection = 1;
int ledcurrentLED = 0;
int ledcount=5;
unsigned long changeTime;
void setup() {
for (int x=0; x<ledcount; x++) {
pinMode(ledPin[x], OUTPUT);
} // set all pins to output
changeTime = millis();
}
void loop() {
if ((millis() - changeTime) > ledDelay) { // if it has been ledDelay ms since last change
changeLED();
changeTime = millis();
}
}
// Increment Function to turn off all LED
void changeLED() {
for (int x=0; x<ledcount; x++) { // Increment x++
digitalWrite(ledPin[x], LOW);
}
// OLD: digitalWrite(ledPin[ledcurrentLED], HIGH); // Turning on the current LED
fadeon (ledPin[ledcurrentLED]);
ledcurrentLED += leddirection; // increment the direction by value
// changing the direction if we reach the last LED
if (ledcurrentLED == ledcount-1) {leddirection = -1;}
if (ledcurrentLED == 0) {leddirection = 1;}
}
// add on
void fadeon(int led) {
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
while (brightness < 255){
// set the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(15);
}
}
Subscribe to:
Posts (Atom)