'목록하단 광고 치환자(withSeok)
728x90
위 광고를 한 번씩 클릭 부탁드립니다. ㅎㅎㅎㅎㅎㅎ
1번째

LED에 불이 1초 간격으로 깜빡깜빡하는 코딩

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <Adafruit_NeoPixel.h>
#define PIN            6  // 하얀선(DATA 또는 DIN)이 연결된 디지털 핀 번호
#define NUMPIXELS      4  // LED 개수
 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
 
void setup() {
  strip.begin();
  strip.show();  // 모든 픽셀을 초기화 (끄기)
}
 
void loop() {
  strip.setPixelColor(0, strip.Color(255,0,0));  // 1번째 LED를 빨간색으로 켜기
  strip.show();
  delay(1000);  // 1초 대기
  
  strip.setPixelColor(0, strip.Color(0,0,0));  // 1번째 LED 끄기
  strip.show();
  delay(1000);  // 1초 대기
}
 
cs
2번째

3개 LED를 사용해서 신호등 처럼 작동하는 코드
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
#include <Adafruit_NeoPixel.h>
#define PIN            6  // 하얀선(DATA 또는 DIN)이 연결된 디지털 핀 번호
#define NUMPIXELS      4  // LED 개수
 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
 
void setup() {
  strip.begin();
  strip.show();  // 모든 픽셀을 초기화 (끄기)
}
 
void loop() {
  // 녹색 LED 켜기 (1번째 LED)
  strip.setPixelColor(0, strip.Color(02550));
  strip.show();
  delay(5000);  // 5초 대기
  
  // 녹색 LED 끄기
  strip.setPixelColor(0, strip.Color(000));
  strip.show();
  // 노란색 LED 켜기 (2번째 LED)
  strip.setPixelColor(1, strip.Color(2552550));
  strip.show();
  delay(2000);  // 2초 대기
  
  // 노란색 LED 끄기
  strip.setPixelColor(1, strip.Color(000));
  strip.show();
  // 빨간색 LED 켜기 (3번째 LED)
  strip.setPixelColor(2, strip.Color(25500));
  strip.show();
  delay(5000);  // 5초 대기
  
  // 빨간색 LED 끄기
  strip.setPixelColor(2, strip.Color(000));
  strip.show();
}
 
cs
3번째

초록색 부분만 다음과 같이 변경
나머지 색은 그대로.

초록색이 처음 5초는 켜져 있다가
마지막 3초부분에 0.5초 간격으로 깜빡깜빡 3번 정도하도록 변경
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
#include <Adafruit_NeoPixel.h>
 
#define PIN            6  // 하얀선(DATA 또는 DIN)이 연결된 디지털 핀 번호
#define NUMPIXELS      4  // LED 개수
 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
 
void setup() {
  strip.begin();
  strip.show(); // 모든 픽셀을 초기화 (끄기)
}
 
void loop() {
  // 녹색 LED 켜기 (1번째 LED) - 처음 5초 동안 켜짐
  strip.setPixelColor(0, strip.Color(02550));
  strip.show();
  delay(5000); // 5초 대기
  
  // 녹색 LED 0.5초 간격으로 깜빡임 - 3번
  for (int i = 0; i < 3; i++) {
    strip.setPixelColor(0, strip.Color(000)); // 끄기
    strip.show();
    delay(500);
    strip.setPixelColor(0, strip.Color(02550)); // 켜기
    strip.show();
    delay(500);
  }
  // 녹색 LED 끄기
  strip.setPixelColor(0, strip.Color(000));
  strip.show();
 
  // 노란색 LED 켜기 (2번째 LED)
  strip.setPixelColor(1, strip.Color(2552550));
  strip.show();
  delay(2000); // 2초 대기
  
  // 노란색 LED 끄기
  strip.setPixelColor(1, strip.Color(000));
  strip.show();
 
  // 빨간색 LED 켜기 (3번째 LED)
  strip.setPixelColor(2, strip.Color(25500));
  strip.show();
  delay(5000); // 5초 대기
  
  // 빨간색 LED 끄기
  strip.setPixelColor(2, strip.Color(000));
  strip.show();
}
 
cs
4번째

경찰차위에 달린 싸이렌등처럼 보이도록 코딩.
2개등을 파란색 나머지 2개등을 빨간색.
파란색과 빨간색이 서로 교대로 불이 들어오는 것 처럼
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
#include <Adafruit_NeoPixel.h>
 
#define PIN            6  // 하얀선(DATA 또는 DIN)이 연결된 디지털 핀 번호
#define NUMPIXELS      4  // LED 개수
 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
 
void setup() {
  strip.begin();
  strip.show(); // 모든 픽셀을 초기화 (끄기)
}
 
void loop() {
  // 파란색 LED 2개 켜기 (1, 2번째 LED)
  strip.setPixelColor(0, strip.Color(00255));
  strip.setPixelColor(1, strip.Color(00255));
  strip.show();
  delay(500); // 0.5초 대기
  
  // 파란색 LED 2개 끄기
  strip.setPixelColor(0, strip.Color(000));
  strip.setPixelColor(1, strip.Color(000));
  strip.show();
 
  // 빨간색 LED 2개 켜기 (3, 4번째 LED)
  strip.setPixelColor(2, strip.Color(25500));
  strip.setPixelColor(3, strip.Color(25500));
  strip.show();
  delay(500); // 0.5초 대기
  
  // 빨간색 LED 2개 끄기
  strip.setPixelColor(2, strip.Color(000));
  strip.setPixelColor(3, strip.Color(000));
  strip.show();
}
 
cs
5번째

가운데 2개등은 빨강1개,파랑1개로 멈춰있고
가쪽 2등은 파란색,빨강색으로 깜빡깜빡하게 해줘
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
#include <Adafruit_NeoPixel.h>
 
#define PIN            6  // 하얀선(DATA 또는 DIN)이 연결된 디지털 핀 번호
#define NUMPIXELS      4  // LED 개수
 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
 
void setup() {
  strip.begin();
  strip.show(); // 모든 픽셀을 초기화 (끄기)
}
 
void loop() {
  // 중앙 2개 LED 설정 (빨강과 파랑으로 멈춰있음)
  strip.setPixelColor(1, strip.Color(25500)); // 빨강
  strip.setPixelColor(2, strip.Color(00255)); // 파랑
  
  // 외곽 2개 LED 파란색으로 켜기
  strip.setPixelColor(0, strip.Color(00255)); 
  strip.setPixelColor(3, strip.Color(00255));
  strip.show();
  delay(500); // 0.5초 대기
  
  // 외곽 2개 LED 빨간색으로 켜기
  strip.setPixelColor(0, strip.Color(25500));
  strip.setPixelColor(3, strip.Color(25500));
  strip.show();
  delay(500); // 0.5초 대기
}
 
cs
6번째

무지개색 변화
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
#include <Adafruit_NeoPixel.h>
 
#define PIN            6  // 하얀선(DATA 또는 DIN)이 연결된 디지털 핀 번호
#define NUMPIXELS      4  // LED 개수
 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
 
void setup() {
  strip.begin();
  strip.show(); // 모든 픽셀을 초기화 (끄기)
}
 
void loop() {
  rainbowCycle(20);
}
 
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;
 
  for(j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
    for(i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}
 
// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 30, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3255 - WheelPos * 30);
}
 
cs

 

 

728x90

'■ Computer > ㅡArduino' 카테고리의 다른 글

울산과학관_스마트홈_버튼_창문_LED  (0) 2023.12.10
아두이노 설치  (0) 2023.10.24
10월17일  (0) 2023.10.17
전하이동행정복지센터.230909  (0) 2023.09.09
Huskylens & Arduino  (0) 2023.01.17

+ Recent posts