게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
아두이노 코드 질문글 여기에 괜찮을까요!!?!?(FSR,LED)
게시물ID : programmer_11019짧은주소 복사하기
작성자 : 긍정대마왕
추천 : 0
조회수 : 805회
댓글수 : 4개
등록시간 : 2015/06/08 12:27:17
옵션
  • 창작글
  • 베스트금지
  • 본인삭제금지
아두이노 구매한지 얼마안되서 아직 예제보고 따라만들고 보면서 신기해하는 수준입니다~!! ㅎㅎ
 
제가 FSR신호를 입력받는 프로그램과 Neopixel LED를 키는 프로그램을 따로 돌리고나서
 
FSR신호 크기에따라 일정값이상이되면 LED가 켜지고 다시 압력이 없어지면 꺼지게 두가지코드를 합치고싶습니다.
 
원래 압력센서의 코드가
 
int FSRpin = 0;
int Vo;
float Rfsr;
void setup() {  
  Serial.begin(9600); 
}
void loop()
{
Vo = analogRead(FSRpin);
  Rfsr = ((9.78 * Vo)/(1-(Vo/1023.0)));
  Serial.print("Rfsr: ");
  Serial.println(Rfsr); 
}
 
이것으로 연속으로 계속 신호를 받아서 모니터에 표시해주는 코드이구요
 
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
 
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
 

  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}
void loop() {
 
  colorWipe(strip.Color(255, 0, 0), 50); // Red
  colorWipe(strip.Color(0, 255, 0), 50); // Green
  colorWipe(strip.Color(0, 0, 255), 50); // Blue
 
  theaterChase(strip.Color(127, 127, 127), 50); // White
  theaterChase(strip.Color(127,   0,   0), 50); // Red
  theaterChase(strip.Color(  0,   0, 127), 50); // Blue
  rainbow(20);
  rainbowCycle(20);
  theaterChaseRainbow(50);
}

void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}
void rainbow(uint8_t wait) {
  uint16_t i, j;
  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

void rainbowCycle(uint8_t wait) {
  uint16_t i, j;
  for(j=0; j<256*5; j++) {
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) {
    for (int q=0; q < 3; q++) {
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c); 
      }
      strip.show();
    
      delay(wait);
    
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);  
      }
    }
  }
}

void theaterChaseRainbow(uint8_t wait) {
  for (int j=0; j < 256; j++) {   
    for (int q=0; q < 3; q++) {
        for (int i=0; i < strip.numPixels(); i=i+3) {
          strip.setPixelColor(i+q, Wheel( (i+j) % 255)); 
        }
        strip.show();
      
        delay(wait);
      
        for (int i=0; i < strip.numPixels(); i=i+3) {
          strip.setPixelColor(i+q, 0);    
        }
    }
  }
}

uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else if(WheelPos < 170) {
    WheelPos -= 85;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  }
}
 
이건 LED 예제에있는 LED 작동코드입니다.
 
이 2가지 코드는 따로 작성시 잘 돌아가구요(당연히... 원래있는 코드이므로... ㅡㅡㅋ)
 
이 두가지를 합친코드를 제가 짜집기로 붙여봤는데 1번밖에 작동이 되지않는 이유가 궁금합니다! (합친코드는 댓글에)
 
읽어주셔서 감사합니다.
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호