Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Multi PWM handler
- #include <Arduino.h>
- #include <TimerOne.h>
- #define MAX_LED 9
- unsigned char PWMcounter = 0;
- unsigned char PWM1 = 50;
- unsigned char tmp_i;
- struct led {
- unsigned char pin;
- unsigned char PWMlevel;
- bool status;
- bool last_status;
- };
- led leds[MAX_LED] = { {.pin=2, .PWMlevel=5},
- {.pin=3, .PWMlevel=10},
- {.pin=4, .PWMlevel=15},
- {.pin=5, .PWMlevel=20},
- {.pin=6, .PWMlevel=25},
- {.pin=7, .PWMlevel=30},
- {.pin=8, .PWMlevel=35},
- {.pin=9, .PWMlevel=40},
- {.pin=10, .PWMlevel=45}};
- void multiPWMhandler () {
- PWMcounter++;
- if (PWMcounter>50) PWMcounter = 0;
- for (tmp_i=0; tmp_i<MAX_LED; tmp_i++) {
- leds[tmp_i].status = PWMcounter < leds[tmp_i].PWMlevel;
- if (leds[tmp_i].status != leds[tmp_i].last_status) {
- leds[tmp_i].last_status = leds[tmp_i].status;
- digitalWrite(leds[tmp_i].pin,leds[tmp_i].status);
- }
- /* if (PWMcounter < leds[tmp_i].PWMlevel) digitalWrite(leds[tmp_i].pin,HIGH);
- else digitalWrite(leds[tmp_i].pin,LOW); */
- }
- }
- void setup() {
- for (tmp_i=0; tmp_i<MAX_LED; tmp_i++) {
- pinMode(leds[tmp_i].pin, OUTPUT);
- leds[tmp_i].status = false;
- leds[tmp_i].last_status = true;
- }
- Timer1.initialize(100); // Run every 0.00001 seconds 10Khz
- Timer1.attachInterrupt(multiPWMhandler);
- }
- void loop() {
- }
- RAW Paste Data
- #include <Arduino.h>
- #include <TimerOne.h>
- #define MAX_LED 9
- unsigned char PWMcounter = 0;
- unsigned char PWM1 = 50;
- unsigned char tmp_i;
- struct led {
- unsigned char pin;
- unsigned char PWMlevel;
- bool status;
- bool last_status;
- };
- led leds[MAX_LED] = { {.pin=2, .PWMlevel=5},
- {.pin=3, .PWMlevel=10},
- {.pin=4, .PWMlevel=15},
- {.pin=5, .PWMlevel=20},
- {.pin=6, .PWMlevel=25},
- {.pin=7, .PWMlevel=30},
- {.pin=8, .PWMlevel=35},
- {.pin=9, .PWMlevel=40},
- {.pin=10, .PWMlevel=45}};
- void multiPWMhandler () {
- PWMcounter++;
- if (PWMcounter>50) PWMcounter = 0;
- for (tmp_i=0; tmp_i<MAX_LED; tmp_i++) {
- leds[tmp_i].status = PWMcounter < leds[tmp_i].PWMlevel;
- if (leds[tmp_i].status != leds[tmp_i].last_status) {
- leds[tmp_i].last_status = leds[tmp_i].status;
- digitalWrite(leds[tmp_i].pin,leds[tmp_i].status);
- }
- /* if (PWMcounter < leds[tmp_i].PWMlevel) digitalWrite(leds[tmp_i].pin,HIGH);
- else digitalWrite(leds[tmp_i].pin,LOW); */
- }
- }
- void setup() {
- for (tmp_i=0; tmp_i<MAX_LED; tmp_i++) {
- pinMode(leds[tmp_i].pin, OUTPUT);
- leds[tmp_i].status = false;
- leds[tmp_i].last_status = true;
- }
- Timer1.initialize(100); // Run every 0.00001 seconds 10Khz
- Timer1.attachInterrupt(multiPWMhandler);
- }
- void loop() {
- }
- My Pastes
- Nothing here yet...
- Public Pastes
- Untitled
- MatLab | 6 min ago
- hw061
- C | 7 min ago
- u6-4.5.1
- Python | 17 min ago
- Задание 4.5.1
- Python | 28 min ago
- Untitled
- JavaScript | 39 min ago
- ReactorControl3
- Lua | 51 min ago
- Script - Classific...
- Lua | 1 hour ago
- PlayerMovement.cs...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement