Require components for test 3.3V:
1x Arduino Uno
1x red wire
1x black wire
1x HW-481 CNT5
Code effect 1:
const byte PIN_OUTPUT = 11;
void setup() {
pinMode(PIN_OUTPUT, OUTPUT);
digitalWrite(PIN_OUTPUT, HIGH);
}
void loop() {}
Require components for test pin:
1x Arduino Uno
2x red wire
2x black wire
1x HW-481 CNT5
Code effect 2:
const byte PIN_OUTPUT = 11; // the PWM pin the LED is attached to
byte brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
void setup() {
pinMode(PIN_OUTPUT, OUTPUT); // declare pin output
}
void loop() {
analogWrite(PIN_OUTPUT, brightness); // set the brightness of pin
brightness = brightness + fadeAmount; // change the brightness for next time through the loop
if (brightness <= 0 || brightness >= 255) { // reverse the direction of the fading at the ends of the fade
fadeAmount = -fadeAmount;
}
delay(30); // wait for 30 milliseconds to see the dimming effect
}
Code effect 3:
const byte PIN_OUTPUT = 11; // the PWM pin the LED is attached to
const byte FADE_AMOUNT = 5; // how many points to fade the LED by
const byte DELAY_DIMMING_EFFECT = 30; // milisecond
const unsigned short DELAY_FLASH_EFFECT = 10000; // milisecond
const unsigned short DELAY_END_ANIMATION = 3000; // milisecond
void setup() {
pinMode(PIN_OUTPUT, OUTPUT); // declare pin output
}
void loop() {
for(short brightness = 0; brightness <= 255; brightness += FADE_AMOUNT) {
analogWrite(PIN_OUTPUT, brightness); // set fade in
delay(DELAY_DIMMING_EFFECT);
}
delay(DELAY_FLASH_EFFECT); // default flash effect
for(short brightness = 255 - FADE_AMOUNT; brightness >= 0; brightness -= FADE_AMOUNT) {
analogWrite(PIN_OUTPUT, brightness); // set fade out
delay(DELAY_DIMMING_EFFECT);
}
delay(DELAY_END_ANIMATION); // turn off
}
Video:
No comments:
Post a Comment