-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLED.cpp
More file actions
92 lines (91 loc) · 1.87 KB
/
Copy pathLED.cpp
File metadata and controls
92 lines (91 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <Arduino.h>
#include "LED.h"
LED::LED(int channel, int* a){
_channel = channel;
for(int i = 0 ; i < channel; i ++)
{
_pins[i] = a[i] ;
pinMode(_pins[i],OUTPUT);
}
}
void LED :: BlinkAll(int delay_ms)
{
for (int i = 0 ; i<_channel;i++)
{
digitalWrite(_pins[i],HIGH);
}
delay(delay_ms);
for (int i = 0 ; i<_channel;i++)
{
digitalWrite(_pins[i],LOW);
}
delay(delay_ms);
}
void LED :: LeftToRight(int numberofLEDs, int delay_ms)
{
// Setting All the LED to LOW on Start
for(int i =0 ;i<_channel; i++)
{
digitalWrite(_pins[i], LOW);
}
// looping within the given LED channel limit -Steps of LED progress
for(int i = 0 ;i<_channel; i =i+numberofLEDs)
{
for(int k =0 ;k<_channel; k++)
{
digitalWrite(_pins[k], LOW);
}
// Setting given numberof LEDs to glow on each step
for (int j=i; j< (i+numberofLEDs) ;j++)
{
digitalWrite(_pins[j], HIGH);
}
delay(delay_ms);
}
}
void LED :: RightToLeft(int numberofLEDs,int delay_ms)
{
for(int i =_channel-1 ;i>=0; i--)
{
digitalWrite(_pins[i], LOW);
}
for(int i = _channel-1 ;i>=0; i=i-numberofLEDs )
{
for(int k =0 ;k<_channel; k++)
{
digitalWrite(_pins[k], LOW);
}
for (int j = i ; j > (i-numberofLEDs); j--)
{
digitalWrite(_pins[j], HIGH);
}
delay(delay_ms);
}
}
void LED :: BlinkAlternate(int delay_ms)
{
for (int i= 0 ; i < _channel;i ++)
{
digitalWrite(_pins[i], LOW);
}
for (int i = 0 ; i < _channel;i ++)
{
if (i % 2 == 0)
{
digitalWrite(_pins[i],HIGH);
}
}
delay(delay_ms);
for (int i=0 ; i < _channel;i ++)
{
digitalWrite(_pins[i], LOW);
}
for (int i = 0 ; i < _channel;i ++)
{
if (i % 2 != 0)
{
digitalWrite(_pins[i],HIGH);
}
}
delay(delay_ms);
}