๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Projects

[Arduino] ์•„๋‘์ด๋…ธ๋กœ ์ž์ทจ๋ฐฉ์„ ๊พธ๋ฉฐ๋ณด์ž - arduino diy led strip

24.12.02 ์ง‘ํ•„ ์‹œ์ž‘

24.12.20 2์ฐจ ์ง‘ํ•„ ๋ฐ ์—…๋กœ๋“œ. ์‚ฌ์ง„ ๋ฐ ๋งํฌ๋ฅผ ์•„์ง ์—…๋กœ๋“œ ์•ˆํ•จ

24.12.24 ์ตœ์ข… ์‚ฌ์ง„ ์—…๋กœ๋“œ ๋ฐ ์ฝ”๋“œ๋ธ”๋Ÿญ ์ ‘๊ธฐ

 

--- INDEX ---

0. ์ค€๋น„๋ฌผ
1. ์ฝ”๋”ฉ
2. ํšŒ๋กœ
3. ๋ชจ๋ธ๋ง
4. 3dํ”„๋ฆฐํŒ…
5. ์™„๋ฃŒ

 

--- --- --- ---

 

0. ์ค€๋น„๋ฌผ


 ์šฐ์„  ๋‚ด๊ฐ€ ๋งŒ๋“ค๊ณ ์‹ถ์€๊ฑด, ๋‚ด ์ˆ ์žฅ์„ ์˜ˆ์˜๊ฒŒ ๊พธ๋ฉฐ์ค„ LED๋‹ค. LED๋Š” ์ž๊ณ ๋กœ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฐ˜์ง์ž„์ด ์žˆ๋Š” ํŽธ์ด ์˜ˆ์˜๋‹ค. ์™„์ „ํ•œ ๊บผ์กŒ๋‹ค ์ผœ์ง์ด ์•„๋‹ˆ๋”๋ผ๋„, ๋ฐ๊ธฐ ์กฐ์ ˆ ๋งŒ์œผ๋กœ๋„ ๋‹จ์กฐ๋กœ์›€์„ ํ•ด๊ฒฐํ•ด ์ค„ ์ˆ˜ ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ด๋ฅผ ๋ณ€ํ™”์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š” ๋‹จ์ˆœํ•œ ๊ตฌ์กฐ๋ฌผ์„ ๋งŒ๋“ค์–ด ๋ณด์•˜๋‹ค.

 

 

 0.1 LED

 ์šฐ์„  ๋‚ด๊ฐ€ ๋งŒ๋“ค๊ณ ์‹ถ์€๊ฑด, ๋‚ด ์ˆ ์žฅ์„ ์˜ˆ์˜๊ฒŒ ๊พธ๋ฉฐ์ค„ LED๋‹ค.

LED๋Š” ์ง์ ‘ ๋งŒ๋“ค๊ณ  ๋œฏ์–ด๊ณ ์น˜๋Š”๊ฑฐ ๋ณด๋‹ค ๋‹ค์ด์†Œ์— 3์ฒ˜๋„Œ์ด๋ฉด ์—„์ฒญ๋งŽ์€ led strip์„ ํŒ๋งคํ•˜๋‹ˆ, ์ด๊ฑธ ์Ÿ์—ฌ๋‘์ž.

์ด๊ฒŒ 3์ฒ˜๋„Œ๋ฐ–์— ์•ˆํ•œ๋‹ค

 

 0.2 ์•„๋‘์ด๋…ธ

 ์ง‘์•ˆ์— ํ•˜๋‚˜์”ฉ ๊ตด๋Ÿฌ๋‹ค๋‹ˆ๋Š” ์•„๋‘์ด๋…ธ ๋‚˜๋…ธ๋ฅผ ์ค€๋น„ํ•œ๋‹ค. -> ์ง‘์—์„œ ๊ตด๋Ÿฌ๋จน๋˜๊ฒŒ ์‚ฌ์‹ค ์ฃฝ์€๊ฑฐ์˜€๋‹ค๋‹ˆ.. ์™ ์ข…์ผ ๋ป˜์ง“๋งŒ ํ•˜๋‹ค๊ฐ€ ์•„๋‘์ด๋…ธ ์šฐ๋…ธ๋กœ ๋Œ์•„์™”๋‹ค. ๋•๋ถ„์— ์‚ฌ์ด์ฆˆ๊ฐ€ ์—„์ฒญ ์ปค์ง„๊ฑด ๋น„๋ฐ€..

 

 0.3 ํ”„๋ฆฐํŒ… ์žฌ๋ฃŒ

 ํฐ์ƒ‰ PLA+์™€ 3dํ”„๋ฆฐํ„ฐ๋ฅผ ์ค€๋น„ํ•œ๋‹ค.

ํ•„์ž์˜ ๊ฒฝ์šฐ๋Š”, ๋ฑ€๋ถ€ X1 ์นด๋ณธ ๋ชจ๋ธ์„ ์ด์šฉํ–ˆ๋‹ค.

 

 0.4 arduino oled

  ์„ ์ด ๋งŽ์€๊ฑด ๋ณต์žกํ•˜๋‹ˆ SPI๋ง๊ณ  I2C๊ฐ€ ์ง€์›๋˜๋Š” ์•„๋‘์ด๋…ธ oled๋ฅผ ์ค€๋น„ํ•œ๋‹ค.

 

 

1. ์ฝ”๋”ฉ

 

์‚ฌ์‹ค ์ฝ”๋”ฉ์€ ๊ทธ๋‹ฅ ์–ด๋ ค์šด๊ฒŒ ์•„๋‹ˆ๋ผ, ๋‹จ์ˆœํ•œ arduino PWM๊ตฌํ˜„๋ฐ–์— ์—†๋‹ค. ๋ฒ„ํŠผ์„ ๋ˆŒ๋ €์„ ๋•Œ, ๋ชจ๋“œ๋ฅผ ๋ณ€๊ฒฝํ•ด ์ค„ ๋””๋ฐ”์šด์‹ฑ์€ ๋ค.

 

 

 

์šฐ์„  led strip์˜ ๋™์ž‘์กฐ๊ฑด์„ ํ™•์ธํ•ด๋ดค๋‹ค.

aa๊ฑด์ „์ง€ ๋‘๊ฐœ์— ํ•ด๋‹นํ•˜๋Š” 3V์—์„œ๋Š” 0.26a๋ฐ–์— ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค. ํ•˜์ง€๋งŒ ์•„๋‘์ด๋…ธ์˜ ์ถœ๋ ฅ์€ 5v 500mA ์ด๊ธฐ ๋•Œ๋ฌธ์— 5V๋ฅผ ๋„ฃ์–ด๋ณด๋‹ˆ, cc๊ฐ€ ๊ฑธ๋ฆฌ๋”๋ผ.. cc๋ฅผ ํ’€์–ด์ฃผ๋‹ˆ 2.38A๊นŒ์ง€ ์น˜์†Ÿ์œผ๋ฉฐ ๋งค์šฐ ๋ฐ์•„์กŒ๋‹ค.

 

์ด๋Ÿฐ ๊ฒฝ์šฐ๋Š” led์˜ ์›๋ž˜ ์ถœ๋ ฅ๋ณด๋‹ค ๋‚ฎ์€ ์ „์••์„ ์ผ๊ธฐ ๋•Œ๋ฌธ์— AA๊ฑด์ „์ง€ ๋‘๊ฐœ ๋งŒ์œผ๋กœ๋„ ์ ์ ˆํ•œ ์ „๋ฅ˜๊ฐ€ ๋ฐ›์ณ์คฌ๋˜ ๊ฒƒ ๊ฐ™๋‹ค. ์›๋ž˜ led๋Š” ์ „์••์„ ๋†’์ด๋ฉด ์•”ํŽ˜์–ด๊ฐ€ ๋” ๊ฐ€ํŒŒ๋ฅด๊ฒŒ ์˜ฌ๋ผ๊ฐ€๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๋Ÿฌํ•œ ์•ˆ์ „์žฅ์น˜๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ์—๋Š” ๊ณผ์—ด๋˜๊ฑฐ๋‚˜ ๊นจ์งˆ ์ˆ˜ ์žˆ์œผ๋‹ˆ ์กฐ์‹ฌํ•œ๋‹ค.

 

 

์•”ํŠผ, ํ•„์ž๋Š” 5๊ฐœ์˜ ๋ชจ๋“œ๋ฅผ ๋งŒ๋“ค์—ˆ๋‹ค.

๊ทธ๋ƒฅ ์ผœ์ ธ์žˆ๋Š”๊ฒƒ๊ณผ ๊นœ๋นก์ด๋Š” ์†๋„๋ฅผ ์กฐ์ ˆํ–ˆ๋‹ค.

์ผ๋‹จ ์ฝ”๋“œ ์ „๋ฌธ์„ ์˜ฌ๋ ค๋ณด์ž๋ฉด,

 

 

 

 

 

 

์ฝ”๋“œ๋ธ”๋Ÿญ์€ ๋„ˆ๋ฌด ๊ธธ์–ด, ๊ธ€์ด ๋„ˆ๋ฌด ๊ธธ์–ด๋ณด์ธ๋‹ค. ๋”ฐ๋ผ์„œ ์ ‘์–ด๋‘์—ˆ๋‹ค.

์•„๋ž˜์˜ ๋”๋ณด๊ธฐ๋ฅผ ๋ˆ„๋ฅด๋ฉด ์ฝ”๋“œ๊ฐ€ ๋‚˜์˜จ๋‹ค.

๋”๋ณด๊ธฐ
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define NUMFLAKES     10 // Number of snowflakes in the animation example

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16

#define XPOS   0 // Indexes into the 'icons' array in function below
#define YPOS   1
#define DELTAY 2

const int mode_changer = 2;
const int oled_changer = 3;
const int led = 11;

bool btn_flag = false;
bool oled_flag = true;
unsigned long current_time = millis();
unsigned long prev_time = millis();
unsigned long current_time_led = millis();
unsigned long prev_time_led = millis();
unsigned long prev_mode_change_time = millis();
unsigned long current_mode_change_time = millis();

volatile int finite_state = 0;

bool fliker_state = HIGH;
bool increasing = true;
bool char_flag = false;
int char_flag_cnt = 0;

int brightness = 0;

int8_t f, icons[NUMFLAKES][3];
static const unsigned char PROGMEM logo_bmp[] =
{ 0b00000000, 0b11000000,
  0b00000001, 0b11000000,
  0b00000001, 0b11000000,
  0b00000011, 0b11100000,
  0b11110011, 0b11100000,
  0b11111110, 0b11111000,
  0b01111110, 0b11111111,
  0b00110011, 0b10011111,
  0b00011111, 0b11111100,
  0b00001101, 0b01110000,
  0b00011011, 0b10100000,
  0b00111111, 0b11100000,
  0b00111111, 0b11110000,
  0b01111100, 0b11110000,
  0b01110000, 0b01110000,
  0b00000000, 0b00110000 };

void setup() {
  pinMode(led,OUTPUT);
  pinMode(mode_changer, INPUT);
  pinMode(oled_changer, INPUT);
  attachInterrupt(digitalPinToInterrupt(mode_changer), interrupt_mode, RISING);
  attachInterrupt(digitalPinToInterrupt(oled_changer), interrupt_oled, RISING);
  Serial.begin(9600);
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  for(f=0; f< NUMFLAKES; f++) {
    icons[f][XPOS]   = random(1 - LOGO_WIDTH, display.width());
    icons[f][YPOS]   = -LOGO_HEIGHT;
    icons[f][DELTAY] = random(1, 6);
  }
  display.display();
  delay(2000); // Pause for 2 seconds
  display.clearDisplay();
  Serial.println("init clear");

}

void loop() {
  //0 is always ON mode ( full power )
  //1 is always ON mode ( half power )
  //2 is slow fliker mode
  //3 is more slow fliker mode
  //4 is super slow non off fliker mode
  if (finite_state == 0) {
    digitalWrite(led,HIGH);
    btn_flag = false;
    Serial.println("state 0 ");
    current_mode_change_time = millis();
    if ((current_mode_change_time - prev_mode_change_time) <= 1500) {
        display.clearDisplay(); // Clear the display buffer
        display.display();
        delay(1);
        
        display.clearDisplay(); // Clear the display buffer
        display.setTextSize(2);             // Normal 1:1 pixel scale
        display.setTextColor(SSD1306_WHITE);        // Draw white text
        display.setCursor(0,0);             // Start at top-left corner
        display.println(F("State0"));
        display.setTextSize(2);             // Normal 1:1 pixel scale
        display.setTextColor(SSD1306_WHITE);        // Draw white text
        display.setCursor(0,16);             // Start at top-left corner
        display.println(F("Always ON"));
        display.setCursor(0,32);             // Start at top-left corner
        display.println(F("FULL POWER"));
      
      
        display.setTextColor(SSD1306_WHITE);
        
        display.display();
        char_flag = true;
        delay(1500);
    }
    else if (oled_flag == true) {
      display.clearDisplay(); // Clear the display buffer

      // Draw each snowflake:
      for(f=0; f< NUMFLAKES; f++) {
        display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, SSD1306_WHITE);
      }

      display.display(); // Show the display buffer on the screen
      // delay(200);        // Pause for 1/10 second

      // Then update coordinates of each flake...
      for(f=0; f< NUMFLAKES; f++) {
        icons[f][YPOS] += icons[f][DELTAY];
        // If snowflake is off the bottom of the screen...
        if (icons[f][YPOS] >= display.height()) {
          // Reinitialize to a random position, just off the top
          icons[f][XPOS]   = random(1 - LOGO_WIDTH, display.width());
          icons[f][YPOS]   = -LOGO_HEIGHT;
          icons[f][DELTAY] = random(1, 6);
        }
      }

    }
    else {
      display.clearDisplay(); // Clear the display buffer
      delay(10);
      // display.display();    
      display.fillRect(0, 0, display.width(), display.height(), SSD1306_BLACK);
      delay(10);
      display.display();    
    }

  }
  else if(finite_state == 1) {
    Serial.println("state 1 ");
    analogWrite(led,127);
    btn_flag = false;
    current_mode_change_time = millis();
    if ((current_mode_change_time - prev_mode_change_time) <= 1500) {
        display.clearDisplay(); // Clear the display buffer
        display.display();
        delay(1);
        
        display.clearDisplay(); // Clear the display buffer
        display.setTextSize(2);             // Normal 1:1 pixel scale
        display.setTextColor(SSD1306_WHITE);        // Draw white text
        display.setCursor(0,0);             // Start at top-left corner
        display.println(F("State1"));
        display.setTextSize(2);             // Normal 1:1 pixel scale
        display.setTextColor(SSD1306_WHITE);        // Draw white text
        display.setCursor(0,16);             // Start at top-left corner
        display.println(F("Always ON"));
        display.setCursor(0,32);             // Start at top-left corner
        display.println(F("HALF POWER"));
      
      
        display.setTextColor(SSD1306_WHITE);
        
        display.display();
        char_flag = true;
        delay(1500);
    }
    else if (oled_flag == true) {
      char_flag = false;
      display.clearDisplay(); // Clear the display buffer
      Serial.println("in else if");

      // Draw each snowflake:
      for(f=0; f< NUMFLAKES; f++) {
        display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, SSD1306_WHITE);
      }

      display.display(); // Show the display buffer on the screen
      // delay(200);        // Pause for 1/10 second

      // Then update coordinates of each flake...
      for(f=0; f< NUMFLAKES; f++) {
        icons[f][YPOS] += icons[f][DELTAY];
        // If snowflake is off the bottom of the screen...
        if (icons[f][YPOS] >= display.height()) {
          // Reinitialize to a random position, just off the top
          icons[f][XPOS]   = random(1 - LOGO_WIDTH, display.width());
          icons[f][YPOS]   = -LOGO_HEIGHT;
          icons[f][DELTAY] = random(1, 6);
        }
      }

    }
    else {
      Serial.println("warnning : in else ");
      display.clearDisplay(); // Clear the display buffer
      delay(10);
      // display.display();    
      display.fillRect(0, 0, display.width(), display.height(), SSD1306_BLACK);
      delay(10);
      display.display();    
    }

  }
  else if(finite_state == 2) {
    Serial.println("state 2 ");
    btn_flag = false;
    current_time_led = millis();
    if (current_time_led >= prev_time_led + 1){
      if (increasing == true) {
        brightness++;
        if (brightness >= 230) {
          increasing = false;
        }
        
      }
      else {
        brightness--;
        if (brightness <= 0) {
          increasing = true;
        }
      }

      analogWrite(led,brightness);
      if (btn_flag == true) {
        return;
      }
      prev_time_led = millis();

    }
    
    current_mode_change_time = millis();
    if ((current_mode_change_time - prev_mode_change_time) <= 1500) {
        display.clearDisplay(); // Clear the display buffer
        display.display();
        delay(1);
        
        display.clearDisplay(); // Clear the display buffer
        display.setTextSize(2);             // Normal 1:1 pixel scale
        display.setTextColor(SSD1306_WHITE);        // Draw white text
        display.setCursor(0,0);             // Start at top-left corner
        display.println(F("State2"));
        display.setTextSize(2);             // Normal 1:1 pixel scale
        display.setTextColor(SSD1306_WHITE);        // Draw white text
        display.setCursor(0,16);             // Start at top-left corner
        display.println(F("Fliker"));
        display.setCursor(0,32);             // Start at top-left corner
        display.println(F("FAST"));
      
      
        display.setTextColor(SSD1306_WHITE);
        
        display.display();
        char_flag = true;
        delay(1500);
    }
    else if (oled_flag == true) {
      display.clearDisplay(); // Clear the display buffer

      // Draw each snowflake:
      for(f=0; f< NUMFLAKES; f++) {
        display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, SSD1306_WHITE);
      }

      display.display(); // Show the display buffer on the screen
      // delay(200);        // Pause for 1/10 second

      // Then update coordinates of each flake...
      for(f=0; f< NUMFLAKES; f++) {
        icons[f][YPOS] += icons[f][DELTAY];
        // If snowflake is off the bottom of the screen...
        if (icons[f][YPOS] >= display.height()) {
          // Reinitialize to a random position, just off the top
          icons[f][XPOS]   = random(1 - LOGO_WIDTH, display.width());
          icons[f][YPOS]   = -LOGO_HEIGHT;
          icons[f][DELTAY] = random(1, 6);
        }
      }

    }
    else {
      display.clearDisplay(); // Clear the display buffer
      delay(10);
      // display.display();    
      display.fillRect(0, 0, display.width(), display.height(), SSD1306_BLACK);
      delay(10);
      display.display();    
    }

  }
  else if(finite_state == 3) {
    Serial.println("state 3 ");
    btn_flag = false;
    current_time_led = millis();
    if (current_time_led >= prev_time_led + 5){
      if (increasing == true) {
        brightness++;
        if (brightness >= 230) {
          increasing = false;
        }
        
      }
      else {
        brightness--;
        if (brightness <= 0) {
          increasing = true;
        }
      }

      analogWrite(led,brightness);
      if (btn_flag == true) {
        return;
      }
      prev_time_led = millis();

    }
    
    current_mode_change_time = millis();
    if ((current_mode_change_time - prev_mode_change_time) <= 1500) {
        display.clearDisplay(); // Clear the display buffer
        display.display();
        delay(1);
        
        display.clearDisplay(); // Clear the display buffer
        display.setTextSize(2);             // Normal 1:1 pixel scale
        display.setTextColor(SSD1306_WHITE);        // Draw white text
        display.setCursor(0,0);             // Start at top-left corner
        display.println(F("State3"));
        display.setTextSize(2);             // Normal 1:1 pixel scale
        display.setTextColor(SSD1306_WHITE);        // Draw white text
        display.setCursor(0,16);             // Start at top-left corner
        display.println(F("Fliker"));
        display.setCursor(0,32);             // Start at top-left corner
        display.println(F("SLOW"));
      
      
        display.setTextColor(SSD1306_WHITE);
        
        display.display();
        char_flag = true;
        delay(1500);
    }
    else if (oled_flag == true) {
      display.clearDisplay(); // Clear the display buffer

      // Draw each snowflake:
      for(f=0; f< NUMFLAKES; f++) {
        display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, SSD1306_WHITE);
      }

      display.display(); // Show the display buffer on the screen
      // delay(200);        // Pause for 1/10 second

      // Then update coordinates of each flake...
      for(f=0; f< NUMFLAKES; f++) {
        icons[f][YPOS] += icons[f][DELTAY];
        // If snowflake is off the bottom of the screen...
        if (icons[f][YPOS] >= display.height()) {
          // Reinitialize to a random position, just off the top
          icons[f][XPOS]   = random(1 - LOGO_WIDTH, display.width());
          icons[f][YPOS]   = -LOGO_HEIGHT;
          icons[f][DELTAY] = random(1, 6);
        }
      }

    }
    else {
      display.clearDisplay(); // Clear the display buffer
      delay(10);
      // display.display();    
      display.fillRect(0, 0, display.width(), display.height(), SSD1306_BLACK);
      delay(10);
      display.display();    
    }

  }
  else if(finite_state == 4) {
    Serial.println("state 4 ");
    btn_flag = false;
    current_time_led = millis();
    if (current_time_led >= prev_time_led + 7){
      if (increasing == true) {
        brightness++;
        if (brightness >= 200) {
          increasing = false;
        }
        
      }
      else {
        brightness--;
        if (brightness <= 25) {
          increasing = true;
        }
      }

      analogWrite(led,brightness);
      if (btn_flag == true) {
        return;
      }
      prev_time_led = millis();
    }
    current_mode_change_time = millis();
 if ((current_mode_change_time - prev_mode_change_time) <= 1500) {
        display.clearDisplay(); // Clear the display buffer
        display.display();
        delay(1);
        
        display.clearDisplay(); // Clear the display buffer
        display.setTextSize(2);             // Normal 1:1 pixel scale
        display.setTextColor(SSD1306_WHITE);        // Draw white text
        display.setCursor(0,0);             // Start at top-left corner
        display.println(F("State4"));
        display.setTextSize(2);             // Normal 1:1 pixel scale
        display.setTextColor(SSD1306_WHITE);        // Draw white text
        display.setCursor(0,16);             // Start at top-left corner
        display.println(F("Fliker"));
        display.setCursor(0,32);             // Start at top-left corner
        display.println(F("SUPER SLOW"));
      
      
        display.setTextColor(SSD1306_WHITE);
        
        display.display();
        char_flag = true;
        delay(1500);
    }
 else if (oled_flag == true) {
      display.clearDisplay(); // Clear the display buffer

      // Draw each snowflake:
      for(f=0; f< NUMFLAKES; f++) {
        display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, SSD1306_WHITE);
      }

      display.display(); // Show the display buffer on the screen
      // delay(200);        // Pause for 1/10 second

      // Then update coordinates of each flake...
      for(f=0; f< NUMFLAKES; f++) {
        icons[f][YPOS] += icons[f][DELTAY];
        // If snowflake is off the bottom of the screen...
        if (icons[f][YPOS] >= display.height()) {
          // Reinitialize to a random position, just off the top
          icons[f][XPOS]   = random(1 - LOGO_WIDTH, display.width());
          icons[f][YPOS]   = -LOGO_HEIGHT;
          icons[f][DELTAY] = random(1, 6);
        }
      }

    }
    else {
      display.clearDisplay(); // Clear the display buffer
      delay(10);
      // display.display();    
      display.fillRect(0, 0, display.width(), display.height(), SSD1306_BLACK);
      delay(10);
      display.display();    
    }




  }
  else {
    Serial.println("incorrect state");

  }
  
   
  

}

void interrupt_mode() {
  current_time = millis();
  if (digitalRead(mode_changer) > 0 ){
    if(current_time > (prev_time + 200)) {
      btn_flag = true;
      if( finite_state >= 4) {
        finite_state = 0;
      }
      else {
        finite_state++;
      }
      prev_time = current_time;
      prev_mode_change_time = millis();
    }
  }
}

void interrupt_oled() {
  Serial.println("interrupted");
  current_time = millis();
  if (digitalRead(oled_changer) > 0 ){
    if(current_time > (prev_time + 200)) {
      if (oled_flag == true) {
        oled_flag = false;
      }
      else {
        Serial.println("clear!");
        
        for(f=0; f< NUMFLAKES; f++) {
          icons[f][XPOS]   = random(1 - LOGO_WIDTH, display.width());
          icons[f][YPOS]   = -LOGO_HEIGHT;
          icons[f][DELTAY] = random(1, 6);
          
        }
        // display.display();
        oled_flag = true;
      }
      prev_time = current_time;
    }
  }

}


void testanimate_step(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  static int8_t icons[NUMFLAKES][3]; // Snowflake data (persistent across calls)
  static bool initialized = false;  // Ensure icons are initialized only once

  // Initialize snowflakes only once
  if (!initialized) {
    for (int f = 0; f < NUMFLAKES; f++) {
      icons[f][XPOS] = random(1 - LOGO_WIDTH, display.width());
      icons[f][YPOS] = -LOGO_HEIGHT;
      icons[f][DELTAY] = random(1, 6);
    }
    initialized = true;
  }

  display.clearDisplay(); // Clear the display buffer

  // Draw each snowflake:
  for (int f = 0; f < NUMFLAKES; f++) {
    display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, SSD1306_WHITE);
  }
  display.display(); // Show the display buffer on the screen

  // Update coordinates of each flake
  for (int f = 0; f < NUMFLAKES; f++) {
    icons[f][YPOS] += icons[f][DELTAY];
    if (icons[f][YPOS] >= display.height()) {
      icons[f][XPOS] = random(1 - LOGO_WIDTH, display.width());
      icons[f][YPOS] = -LOGO_HEIGHT;
      icons[f][DELTAY] = random(1, 6);
    }
  }
}

 

 

 

 

์ด๋ ‡๊ฒŒ ์กฐ๊ธˆ ๊ธด ์ฝ”๋“œ๊ฐ€ ์™„์„ฑ๋˜์—ˆ๋‹ค.

์‚ฌ์‹ค led๋งŒ ์‚ฌ์šฉํ•˜๋ฉด ์ด๋ ‡๊ฒŒ ๊ธธ์–ด์งˆ ์ด์œ ๊ฐ€ ์—†์ง€๋งŒ, oled๋ฅผ ์‚ฌ์šฉํ•ด ์กฐ๊ธˆ ๊ธธ์–ด์กŒ๋‹ค.

๋Œ€์ถฉ ๋™์ž‘์„ ์„ค๋ช…ํ•˜๋ฉด, ๋ฒ„ํŠผ์„ ๋‘ ๊ฐœ ๋งŒ๋“ค์–ด์„œ ํ•˜๋‚˜๋Š” oled์˜ ํ”ผ๋กœ๋„๋ฅผ ์•„๋ผ๊ธฐ ์œ„ํ•ด ์ผœ๊ณ  ๋„๋Š” ๋ฒ„ํŠผ์„ ๋งŒ๋“ค์—ˆ๊ณ , ํ•˜๋‚˜๋Š” led strip์˜ state๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ๋ฒ„ํŠผ์„ ๋งŒ๋“ค์—ˆ๋‹ค. oled์˜ ํ”ผ๋กœ๋„๋ฅผ ์ƒ๊ฐํ•˜๊ฒŒ ๋œ๊ฑด, ์‚ฌ์‹ค ์•„๋ž˜์™€ ๊ฐ™์ด ๋ณ„๋“ค์ด ๋ฌด์ˆ˜ํžˆ ๋–จ์–ด์ง€๋Š” ์›€์งค์„ ๋„ฃ์—ˆ๊ธฐ ๋•Œ๋ฌธ์ธ๋ฐ, ์ด๊ฒŒ ์˜ˆ์ œ์— ์žˆ์—ˆ๋Š”๋ฐ ํฌ๋ฆฌ์Šค๋งˆ์Šค์™€ ์ข€ ์–ด์šธ๋ฆฌ๋Š” ๋“ฏ ํ•˜์—ฌ ๊ทธ๋Œ€๋กœ ๊ฐ€์ ธ์˜ค๊ฒŒ ๋˜์—ˆ๋‹ค.

(์ขŒ) ๋ณ„์ด ๋ฌด์ˆ˜ํžˆ ๋–จ์–ด์ง€๋Š” idle ์ƒํƒœ, (์šฐ) state ๋ณ€๊ฒฝ์‹œ ์ž ๊น ๋œจ๋Š” ์•ˆ๋‚ด๋ฌธ๊ตฌ

 

๋ณ„๊ณผ ๊ธ€์”จ๊ฐ€ ์ž˜๋ฆฌ๋Š” ์ด์œ ๋Š” ๋‹จ์ˆœํžˆ ์ฃผ์‚ฌ์œจ ๋•Œ๋ฌธ์ด๋‹ค.

 

 

2. ํšŒ๋กœ

์‚ฌ์‹ค ์ด๋Ÿฐ ํ”„๋กœ์ ํŠธ์—์„œ ํšŒ๋กœ๋Š”, ๋‚ฉ๋•œ์„ ํ•ด์•ผํ•˜๊ธฐ์— ๊ธฐ์กด์— ๊ฐ€์ง„ ์„ค๊ณ„ ํˆด๋กœ ๊ตฌ์ƒ๊ณผ ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ํ•ด์•ผ ํ•˜์ง€๋งŒ, ์ด ํ”„๋กœ์ ํŠธ๋Š” ํšŒ๋กœ๊ฐ€ ๋„ˆ๋ฌด ๋‹จ์ˆœํ•ด ๊ทธ๋ƒฅ ๊ทธ์ž๋ฆฌ์—์„œ ์ฆ‰์„์œผ๋กœ ํ•ด๋ฒ„๋ ธ๋‹ค. ๊ตฌ์ƒ๋ถ€ํ„ฐ ๋‚ฉ๋•œ ๋ฐ ํ…Œ์ŠคํŠธ๊นŒ์ง€ ๋„ค์‹œ๊ฐ„ ์ •๋„ ๊ฑธ๋ ธ๋˜ ๊ฒƒ ๊ฐ™๋‹ค.

๋‹จ์ˆœํžˆ 3.3V๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ํ’€๋‹ค์šด ์ €ํ•ญ์„ ์ด์šฉํ•ด interrupt๋ฅผ ๊ตฌํ˜„ํ•œ ๋ฒ„ํŠผ ๋‘๊ฐœ์™€ oled๋ฅผ ํ•˜๋‚˜ ์žฅ์ฐฉํ–ˆ๋‹ค. ์œ„์ชฝ์— ๋ณด๋ฉด ํ’€๋‹ค์šด์„ ์œ„ํ•œ 1k ohm ์ €ํ•ญ ๋‘๊ฐœ๊ฐ€ ๋ณด์ผ๊ฒƒ์ด๋‹ค.

 

 

 

 

 

 

3. ๋ชจ๋ธ๋ง

๋‹ค์Œ์€ ๋ชจ๋ธ๋ง์ด๋‹ค. ์•„๋ฌด๋ฆฌ ๋‚ด์šฉ๋ฌผ์ด ์ข‹๋‹ค ํ•˜๋”๋ผ๋„ ์•ˆ์˜ˆ์˜๋ฉด ๋ง์งฑ ๋„๋ฃจ๋ฌต์ด๋‹ค.

์ ๋‹นํ•œ ์ผ€์ด์Šค๋ฅผ ๋งŒ๋“ค๊ณ , ์•„๋‘์ด๋…ธ๋ฅผ ๋ผ์›Œ๋„ฃ์„ ์ˆ˜ ์žˆ๋„๋ก ์•„๋‘์ด๋…ธ์˜ ์›๋ž˜ ๋‚˜์‚ฌ๊ตฌ๋ช… ๋„ค๊ฐœ์˜ ์ˆ˜์น˜๋ฅผ ๋ฒ„๋‹ˆ์–ด์บ˜๋ฆฌํผ๋กœ ์ธก์ •ํ•ด ๋งŒ๋“ค์—ˆ๋‹ค. ์‚ฌ์‹ค ์ด ๋ชจ๋ธ๋ง์„ printingํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋ณธ์ธ์ด ๊ฐ–๊ณ ์žˆ๋Š” ํ”„๋ฆฐํ„ฐ์˜ ์ถœ๋ ฅ๊ณต์ฐจ๋ฅผ ์•Œ๊ณ ์žˆ์–ด์•ผ ํ•˜๋Š”๋ฐ, ํ•„์ž์˜ ๊ฒฝ์šฐ๋Š” ์ฒ˜์Œ ์“ฐ๋Š” ํ”„๋ฆฐํ„ฐ๋ฅผ ์‚ฌ์šฉํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์„ธ ๋ฒˆ ์ •๋„์˜ ์‹œํ–‰์ฐฉ์˜ค๋ฅผ ๊ฑฐ์ณค๋‹ค. ์ƒ‰์ƒ์— ๋”ฐ๋ผ์„œ ์ถœ๋ ฅ๊ณต์ฐจ๋‚˜ ์ˆ˜์ถ•๋ฅ ์ด ๋ฐ”๋€Œ๋Š”๊ฒƒ๋„ ์•Œ๊ณ ์žˆ์–ด์•ผ ํ•œ๋‹ค.

์ด๋ ‡๊ฒŒ ์ผ€์ด์Šค์™€ ๋ฒ„ํŠผ์„ ๋ชจ๋ธ๋ง ํ–ˆ๋‹ค.

๋ฒ„ํŠผ์€ ๋ฐ”๊นฅ์—์„œ ๋ˆ„๋ฅด๊ฑฐ๋‚˜ ์žก์•„๋‹น๊ฒผ์„ ๋•Œ ๋น ์ง€์ง€ ์•Š๋„๋ก T์žํ˜•์œผ๋กœ ์„ค๊ณ„ํ–ˆ๋‹ค.

 

4. 3dํ”„๋ฆฐํŒ…

 

์ƒ๊ฐ๋ณด๋‹ค ์ž˜ ๋‚˜์™”๊ณ , ๋ฐ”๋กœ ์•„๋‘์ด๋…ธ๊ฐ€ ๋ผ์›Œ์ง„ ์ฑ„ ๊ณ ์ •์ด ๋๋‹ค.

 

 

5. ์™„๋ฃŒ

 

 

xrated ๊ธ€๋ผ์Šค๋Š” ๋ณ„๋กœ ์“ธ ์ผ์ด ์—†์–ด์„œ ๊ทธ๋ƒฅ led strip์˜ ๋‚จ๋Š” ๋ถ€๋ถ„์„ ์ „๋ถ€ ์‘ค์…”๋„ฃ์—ˆ๋‹ค

์ด๋ ‡๊ฒŒ ๋ณด๋‹ˆ, ์œ—์ธต์˜ ์ˆ ์žฅ์ด ์ž˜ ์•ˆ๋ณด์ด์ง€๋งŒ ๊ทธ๋ƒฅ ์“ธ๋ จ๋‹ค..

 

๋ฒ„ํŠผ์œผ๋กœ ๋ชจ๋“œ ๋ณ€๊ฒฝํ•˜๊ณ  oled๋„ ๊ป๋‹ค์ผฐ๋‹ค ํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ ์—ฌ๋Ÿฌ ๋ชจ๋“œ๋ฅผ ์ฆ๊ธฐ๊ณ , oled์˜ ์ˆ˜๋ช…๋„ ๊ณ ๋ คํ•  ์ˆ˜ ์žˆ๋‹ค.

์ด๋ ‡๊ฒŒ ๋ณด๋ฉด ์•ฝ๊ฐ„์€ ๋‚ญ๋งŒ์ด ์žˆ์ง€ ์•Š์€๊ฐ€

 

 

์—ฌ๋‹ด

์ด๊ณต๊ณ„๋“ค์€ ์‚ฌ์‹ค ๋‚ญ๋งŒ์„ ์ถ”๊ตฌํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ ์ถ”๊ตฌํ•˜์ง€ ์•Š๋Š”๋‹ค. ๊ทธ๋“ค์€ ๋Œ€์ฒด๋กœ ๊ธฐ๋Šฅ์ฃผ์˜์ ์ด๋ฉฐ, ๋ณธ์งˆ์— ๋Œ€ํ•œ ์ดํ•ด๋ฅผ ์ถ”๊ตฌํ•˜๋Š” ์‚ฌ๊ณ ๋ฅผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ทธ๋“ค์ด ์ถ”๊ตฌํ•˜๋Š” ๋‚ญ๋งŒ์€ ๋‹ค๋ฅธ ์‚ฌ๋žŒ๋“ค์ด ์ƒ๊ฐํ•˜๋Š” ๊ฒƒ๊ณผ๋Š” ์กฐ๊ธˆ ๋‹ค๋ฅธ ๊ณณ์— ์žˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด๋Ÿฐ ๋‚ญ๋งŒ๋“ค์€ ๋ณธ์งˆ์ ์œผ๋กœ ์ถ”๊ตฌํ•˜๋Š” ๋ฐ”๊ฐ€ ๊ฐ™์œผ๋ฉฐ, ์ด๊ณต๊ณ„๋˜ ์˜ˆ์ฒด๋Šฅ์ด๋˜ ์„œ๋กœ์˜ ๋‚ญ๋งŒ์„ ์กด์ค‘ํ•ด์ฃผ๊ธฐ ๋ฐ”๋ผ๋ฉฐ, ํ•„์ž๋Š” ๊ฐ ๋ถ„์•ผ์˜ ๋‚ญ๋งŒ๋“ค์ด ์œตํ•ฉ๋ ๋•Œ ๋น„๋กœ์„œ ์™„๋ฒฝํ•œ ๋‚ญ๋งŒ์ด ๋‚˜์˜ฌ ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•œ๋‹ค. ๊ทธ๋Ÿฌํ•œ ์˜ˆ์‹œ๋“ค์ด ๋””์ž์ธ๊ณผ ๊ณตํ•™์˜ ๊ฒฐํ•ฉ์ฒด์ธ ์ œํ’ˆ๋“ค์ด๋‹ค.

'Projects' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[VScode & Git] windows์—์„œ VScode์™€ git์„ ์—ฐ๋™ํ•ด๋ณด์ž.  (0) 2025.04.24