// 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).
}
이렇게 구부림감지센서가 인식될때마다 네오픽셀이 켜지도록 코딩을 짰는데 뭐가 문제인지 안켜지네요..ㅠㅠ
|