정보나눔

오픈소스하드웨어 프로젝트에 대한 다양한 정보를 나누는 공간입니다.

네오픽셀이 안켜져요ㅜㅜ
joyejin33 | 2018-06-23

// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

 

#define PIN            6

#define NUMPIXELS      27

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 500;
int flexpin = A5; 

void setup() {
  
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
 
pinMode (flexpin,INPUT);

Serial.begin(9600); 
}


void loop() {

  //센서값을 저장할 변수 설정
  int flexVal; 
  // 센서로 부터 보내오는 값을 입력 받는다.(0-1023)
  flexVal = analogRead(flexpin); 
  Serial.print("sensor: ");
  // sensor:XXX 로 출력한다(XXX값은 센서로 부터 읽어 온 값)
  Serial.println(flexVal); 
  
  delay(1000);

 

   if(400 < flexVal < 1023){
          // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
           pixels.show(); 
    pixels.setPixelColor(0, pixels.Color(150,0,0)); 
  pixels.setPixelColor(1, pixels.Color(150,0,0));
  pixels.setPixelColor(2, pixels.Color(150,0,0));
  pixels.setPixelColor(3, pixels.Color(0,0,0));
    pixels.setPixelColor(4, pixels.Color(0,0,0)); 
  pixels.setPixelColor(5, pixels.Color(0,0,0));
  pixels.setPixelColor(6, pixels.Color(0,0,0));
  pixels.setPixelColor(7, pixels.Color(0,0,0));
    pixels.setPixelColor(8, pixels.Color(0,0,0)); 
  pixels.setPixelColor(9, pixels.Color(0,0,0));
  pixels.setPixelColor(10, pixels.Color(0,0,0));
  pixels.setPixelColor(11, pixels.Color(0,0,0));
    pixels.setPixelColor(12, pixels.Color(0,0,0)); 
  pixels.setPixelColor(13, pixels.Color(0,0,0));
  pixels.setPixelColor(14, pixels.Color(0,0,0));
  pixels.setPixelColor(15, pixels.Color(0,0,0));
    pixels.setPixelColor(16, pixels.Color(0,0,0)); 
  pixels.setPixelColor(17, pixels.Color(0,0,0));
  pixels.setPixelColor(18, pixels.Color(0,0,0));
  pixels.setPixelColor(19, pixels.Color(0,0,0));
    pixels.setPixelColor(20, pixels.Color(0,0,0));
    pixels.setPixelColor(21, pixels.Color(0,0,0));
    pixels.setPixelColor(22, pixels.Color(0,0,0));
    pixels.setPixelColor(23, pixels.Color(0,0,0));
    pixels.setPixelColor(24, pixels.Color(0,0,0));
    pixels.setPixelColor(25, pixels.Color(0,0,0));
    pixels.setPixelColor(26, pixels.Color(0,0,0));
    
      }

      else    if(350< flexVal < 399){
          // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
           pixels.show(); 
    pixels.setPixelColor(0, pixels.Color(150,0,0)); 
  pixels.setPixelColor(1, pixels.Color(150,0,0));
  pixels.setPixelColor(2, pixels.Color(150,0,0));
  pixels.setPixelColor(3, pixels.Color(0,150,0));
  pixels.setPixelColor(4, pixels.Color(0,150,0)); 
  pixels.setPixelColor(5, pixels.Color(0,150,0));
  pixels.setPixelColor(6, pixels.Color(0,0,0));
  pixels.setPixelColor(7, pixels.Color(0,0,0));
  pixels.setPixelColor(8, pixels.Color(0,0,0)); 
  pixels.setPixelColor(9, pixels.Color(0,0,0));
  pixels.setPixelColor(10, pixels.Color(0,0,0));
  pixels.setPixelColor(11, pixels.Color(0,0,0));
  pixels.setPixelColor(12, pixels.Color(0,0,0)); 
  pixels.setPixelColor(13, pixels.Color(0,0,0));
  pixels.setPixelColor(14, pixels.Color(0,0,0));
  pixels.setPixelColor(15, pixels.Color(0,0,0));
  pixels.setPixelColor(16, pixels.Color(0,0,0)); 
  pixels.setPixelColor(17, pixels.Color(0,0,0));
  pixels.setPixelColor(18, pixels.Color(0,0,0));
  pixels.setPixelColor(19, pixels.Color(0,0,0));
  pixels.setPixelColor(20, pixels.Color(0,0,0));
       pixels.setPixelColor(21, pixels.Color(0,0,0));
    pixels.setPixelColor(22, pixels.Color(0,0,0));
    pixels.setPixelColor(23, pixels.Color(0,0,0));
    pixels.setPixelColor(24, pixels.Color(0,0,0));
    pixels.setPixelColor(25, pixels.Color(0,0,0));
    pixels.setPixelColor(26, pixels.Color(0,0,0));
    
      }
 
  else    if(300 < flexVal < 349){
          // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
           pixels.show(); 
    pixels.setPixelColor(0, pixels.Color(150,0,0)); 
  pixels.setPixelColor(1, pixels.Color(150,0,0));
  pixels.setPixelColor(2, pixels.Color(150,0,0));
  pixels.setPixelColor(3, pixels.Color(0,150,0));
  pixels.setPixelColor(4, pixels.Color(0,150,0)); 
  pixels.setPixelColor(5, pixels.Color(0,150,0));
  pixels.setPixelColor(6, pixels.Color(0,0,150));
  pixels.setPixelColor(7, pixels.Color(0,0,150));
  pixels.setPixelColor(8, pixels.Color(0,0,150)); 
  pixels.setPixelColor(9, pixels.Color(0,0,0));
  pixels.setPixelColor(10, pixels.Color(0,0,0));
  pixels.setPixelColor(11, pixels.Color(0,0,0));
  pixels.setPixelColor(12, pixels.Color(0,0,0)); 
  pixels.setPixelColor(13, pixels.Color(0,0,0));
  pixels.setPixelColor(14, pixels.Color(0,0,0));
  pixels.setPixelColor(15, pixels.Color(0,0,0));
  pixels.setPixelColor(16, pixels.Color(0,0,0)); 
  pixels.setPixelColor(17, pixels.Color(0,0,0));
  pixels.setPixelColor(18, pixels.Color(0,0,0));
  pixels.setPixelColor(19, pixels.Color(0,0,0));
  pixels.setPixelColor(20, pixels.Color(0,0,0));
       pixels.setPixelColor(21, pixels.Color(0,0,0));
    pixels.setPixelColor(22, pixels.Color(0,0,0));
    pixels.setPixelColor(23, pixels.Color(0,0,0));
    pixels.setPixelColor(24, pixels.Color(0,0,0));
    pixels.setPixelColor(25, pixels.Color(0,0,0));
    pixels.setPixelColor(26, pixels.Color(0,0,0));
    
      }
      else    if(250 < flexVal < 299 ){
          // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
           pixels.show(); 
    pixels.setPixelColor(0, pixels.Color(150,0,0)); 
  pixels.setPixelColor(1, pixels.Color(150,0,0));
  pixels.setPixelColor(2, pixels.Color(150,0,0));
  pixels.setPixelColor(3, pixels.Color(0,150,0));
  pixels.setPixelColor(4, pixels.Color(0,150,0)); 
  pixels.setPixelColor(5, pixels.Color(0,150,0));
  pixels.setPixelColor(6, pixels.Color(0,0,150));
  pixels.setPixelColor(7, pixels.Color(0,0,150));
  pixels.setPixelColor(8, pixels.Color(0,0,150)); 
  pixels.setPixelColor(9, pixels.Color(150,0,150));
  pixels.setPixelColor(10, pixels.Color(150,0,150));
  pixels.setPixelColor(11, pixels.Color(150,0,150));
  pixels.setPixelColor(12, pixels.Color(0,0,0)); 
  pixels.setPixelColor(13, pixels.Color(0,0,0));
  pixels.setPixelColor(14, pixels.Color(0,0,0));
  pixels.setPixelColor(15, pixels.Color(0,0,0));
  pixels.setPixelColor(16, pixels.Color(0,0,0)); 
  pixels.setPixelColor(17, pixels.Color(0,0,0));
  pixels.setPixelColor(18, pixels.Color(0,0,0));
  pixels.setPixelColor(19, pixels.Color(0,0,0));
  pixels.setPixelColor(20, pixels.Color(0,0,0));
       pixels.setPixelColor(21, pixels.Color(0,0,0));
    pixels.setPixelColor(22, pixels.Color(0,0,0));
    pixels.setPixelColor(23, pixels.Color(0,0,0));
    pixels.setPixelColor(24, pixels.Color(0,0,0));
    pixels.setPixelColor(25, pixels.Color(0,0,0));
    pixels.setPixelColor(26, pixels.Color(0,0,0));
    
      }
 
    else    if(200 < flexVal < 249){
          // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
           pixels.show(); 
    pixels.setPixelColor(0, pixels.Color(150,0,0)); 
  pixels.setPixelColor(1, pixels.Color(150,0,0));
  pixels.setPixelColor(2, pixels.Color(150,0,0));
  pixels.setPixelColor(3, pixels.Color(0,150,0));
  pixels.setPixelColor(4, pixels.Color(0,150,0)); 
  pixels.setPixelColor(5, pixels.Color(0,150,0));
  pixels.setPixelColor(6, pixels.Color(0,0,150));
  pixels.setPixelColor(7, pixels.Color(0,0,150));
  pixels.setPixelColor(8, pixels.Color(0,0,150)); 
  pixels.setPixelColor(9, pixels.Color(150,0,150));
  pixels.setPixelColor(10, pixels.Color(150,0,150));
  pixels.setPixelColor(11, pixels.Color(150,0,150));
  pixels.setPixelColor(12, pixels.Color(0,150,150)); 
  pixels.setPixelColor(13, pixels.Color(0,150,150));
  pixels.setPixelColor(14, pixels.Color(0,150,150));
  pixels.setPixelColor(15, pixels.Color(0,0,0));
  pixels.setPixelColor(16, pixels.Color(0,0,0)); 
  pixels.setPixelColor(17, pixels.Color(0,0,0));
  pixels.setPixelColor(18, pixels.Color(0,0,0));
  pixels.setPixelColor(19, pixels.Color(0,0,0));
  pixels.setPixelColor(20, pixels.Color(0,0,0));
       pixels.setPixelColor(21, pixels.Color(0,0,0));
    pixels.setPixelColor(22, pixels.Color(0,0,0));
    pixels.setPixelColor(23, pixels.Color(0,0,0));
    pixels.setPixelColor(24, pixels.Color(0,0,0));
    pixels.setPixelColor(25, pixels.Color(0,0,0));
    pixels.setPixelColor(26, pixels.Color(0,0,0));
    
      }

     else    if(160 < flexVal< 199 ){
          // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
           pixels.show(); 
    pixels.setPixelColor(0, pixels.Color(150,0,0)); 
  pixels.setPixelColor(1, pixels.Color(150,0,0));
  pixels.setPixelColor(2, pixels.Color(150,0,0));
  pixels.setPixelColor(3, pixels.Color(0,150,0));
  pixels.setPixelColor(4, pixels.Color(0,150,0)); 
  pixels.setPixelColor(5, pixels.Color(0,150,0));
  pixels.setPixelColor(6, pixels.Color(0,0,150));
  pixels.setPixelColor(7, pixels.Color(0,0,150));
  pixels.setPixelColor(8, pixels.Color(0,0,150)); 
  pixels.setPixelColor(9, pixels.Color(150,0,150));
  pixels.setPixelColor(10, pixels.Color(150,0,150));
  pixels.setPixelColor(11, pixels.Color(150,0,150));
  pixels.setPixelColor(12, pixels.Color(0,150,150)); 
  pixels.setPixelColor(13, pixels.Color(0,150,150));
  pixels.setPixelColor(14, pixels.Color(0,150,150));
  pixels.setPixelColor(15, pixels.Color(150,150,0));
  pixels.setPixelColor(16, pixels.Color(150,150,0)); 
  pixels.setPixelColor(17, pixels.Color(150,150,0));
  pixels.setPixelColor(18, pixels.Color(0,0,0));
  pixels.setPixelColor(19, pixels.Color(0,0,0));
  pixels.setPixelColor(20, pixels.Color(0,0,0));
       pixels.setPixelColor(21, pixels.Color(0,0,0));
    pixels.setPixelColor(22, pixels.Color(0,0,0));
    pixels.setPixelColor(23, pixels.Color(0,0,0));
    pixels.setPixelColor(24, pixels.Color(0,0,0));
    pixels.setPixelColor(25, pixels.Color(0,0,0));
    pixels.setPixelColor(26, pixels.Color(0,0,0));
    
      }


        else    if(0 <flexVal < 159 ){
          // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
           pixels.show(); 
    pixels.setPixelColor(0, pixels.Color(150,0,0)); 
  pixels.setPixelColor(1, pixels.Color(150,0,0));
  pixels.setPixelColor(2, pixels.Color(150,0,0));
  pixels.setPixelColor(3, pixels.Color(0,150,0));
  pixels.setPixelColor(4, pixels.Color(0,150,0)); 
  pixels.setPixelColor(5, pixels.Color(0,150,0));
  pixels.setPixelColor(6, pixels.Color(0,0,150));
  pixels.setPixelColor(7, pixels.Color(0,0,150));
  pixels.setPixelColor(8, pixels.Color(0,0,150)); 
  pixels.setPixelColor(9, pixels.Color(150,0,150));
  pixels.setPixelColor(10, pixels.Color(150,0,150));
  pixels.setPixelColor(11, pixels.Color(150,0,150));
  pixels.setPixelColor(12, pixels.Color(0,150,150)); 
  pixels.setPixelColor(13, pixels.Color(0,150,150));
  pixels.setPixelColor(14, pixels.Color(0,150,150));
  pixels.setPixelColor(15, pixels.Color(150,150,0));
  pixels.setPixelColor(16, pixels.Color(150,150,0)); 
  pixels.setPixelColor(17, pixels.Color(150,150,0));
  pixels.setPixelColor(18, pixels.Color(150,150,150));
  pixels.setPixelColor(19, pixels.Color(150,150,150));
  pixels.setPixelColor(20, pixels.Color(150,150,150));
       pixels.setPixelColor(21, pixels.Color(0,0,0));
    pixels.setPixelColor(22, pixels.Color(0,0,0));
    pixels.setPixelColor(23, pixels.Color(0,0,0));
    pixels.setPixelColor(24, pixels.Color(0,0,0));
    pixels.setPixelColor(25, pixels.Color(0,0,0));
    pixels.setPixelColor(26, pixels.Color(0,0,0));
    
      }

    delay(1000); // Delay for a period of time (in milliseconds).
 }

 

이렇게 구부림감지센서가 인식될때마다 네오픽셀이 켜지도록 코딩을 짰는데 뭐가 문제인지 안켜지네요..ㅠㅠ 

 

이전글   |    아두이노 오렌지보드(BLE)와 라즈베리파이3 블루투스 통신 관련 질문있습니다. ... 2018-06-21
다음글   |    AT명령어 사용하여 초음파센서값 thingspeak에 전송 ... 2018-06-25