BASIC4MCU | 질문게시판 | 색상인식과 진동모터
페이지 정보
작성자 아두에듀잉 작성일2019-11-27 21:40 조회3,625회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=10929
본문
안녕하세요 노란색을 감지했을때 진동을 울리게 하고싶은데 코드를 어떻게 해야해서 모르겟습니다 . 아래의 예제까진 했는데 어떤식으로 코드를 넣어야할지 감이안잡힙니다
현재 가지고있는 진동모터 http://mechasolution.com/shop/goods/goods_view.php?goodsno=542193&category=
#include <Wire.h> | |
#include "Adafruit_TCS34725.h" | |
// Pick analog outputs, for the UNO these three work well | |
// use ~560 ohm resistor between Red & Blue, ~1K for green (its brighter) | |
#define redpin 3 | |
#define greenpin 5 | |
#define bluepin 6 | |
// for a common anode LED, connect the common pin to +5V | |
// for common cathode, connect the common to ground | |
// set to false if using a common cathode LED | |
#define commonAnode true | |
// our RGB -> eye-recognized gamma color | |
byte gammatable[256]; | |
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X); | |
void setup() { | |
Serial.begin(9600); | |
//Serial.println("Color View Test!"); | |
if (tcs.begin()) { | |
//Serial.println("Found sensor"); | |
} else { | |
Serial.println("No TCS34725 found ... check your connections"); | |
while (1); // halt! | |
} | |
// use these three pins to drive an LED | |
#if defined(ARDUINO_ARCH_ESP32) | |
ledcAttachPin(redpin, 1); | |
ledcSetup(1, 12000, 8); | |
ledcAttachPin(greenpin, 2); | |
ledcSetup(2, 12000, 8); | |
ledcAttachPin(bluepin, 3); | |
ledcSetup(3, 12000, 8); | |
#else | |
pinMode(redpin, OUTPUT); | |
pinMode(greenpin, OUTPUT); | |
pinMode(bluepin, OUTPUT); | |
#endif | |
// thanks PhilB for this gamma table! | |
// it helps convert RGB colors to what humans see | |
for (int i=0; i<256; i++) { | |
float x = i; | |
x /= 255; | |
x = pow(x, 2.5); | |
x *= 255; | |
if (commonAnode) { | |
gammatable[i] = 255 - x; | |
} else { | |
gammatable[i] = x; | |
} | |
//Serial.println(gammatable[i]); | |
} | |
} | |
// The commented out code in loop is example of getRawData with clear value. | |
// Processing example colorview.pde can work with this kind of data too, but It requires manual conversion to | |
// [0-255] RGB value. You can still uncomments parts of colorview.pde and play with clear value. | |
void loop() { | |
float red, green, blue; | |
tcs.setInterrupt(false); // turn on LED | |
delay(60); // takes 50ms to read | |
tcs.getRGB(&red, &green, &blue); | |
tcs.setInterrupt(true); // turn off LED | |
Serial.print("R:\t"); Serial.print(int(red)); | |
Serial.print("\tG:\t"); Serial.print(int(green)); | |
Serial.print("\tB:\t"); Serial.print(int(blue)); | |
// Serial.print("\t"); | |
// Serial.print((int)red, HEX); Serial.print((int)green, HEX); Serial.print((int)blue, HEX); | |
Serial.print("\n"); | |
// uint16_t red, green, blue, clear; | |
// | |
// tcs.setInterrupt(false); // turn on LED | |
// | |
// delay(60); // takes 50ms to read | |
// | |
// tcs.getRawData(&red, &green, &blue, &clear); | |
// | |
// tcs.setInterrupt(true); // turn off LED | |
// | |
// Serial.print("C:\t"); Serial.print(int(clear)); | |
// Serial.print("R:\t"); Serial.print(int(red)); | |
// Serial.print("\tG:\t"); Serial.print(int(green)); | |
// Serial.print("\tB:\t"); Serial.print(int(blue)); | |
// Serial.println(); | |
#if defined(ARDUINO_ARCH_ESP32) | |
ledcWrite(1, gammatable[(int)red]); | |
ledcWrite(2, gammatable[(int)green]); | |
ledcWrite(3, gammatable[(int)blue]); | |
#else | |
analogWrite(redpin, gammatable[(int)red]); | |
analogWrite(greenpin, gammatable[(int)green]); | |
analogWrite(bluepin, gammatable[(int)blue]); | |
#endif | |
} |
댓글 0
조회수 3,625등록된 댓글이 없습니다.