磁悬浮交互式蓝牙音响
https://www.elecfans.com/project/604?mobile=2
代码
- #include
- #define PIN 6
- #define NUMPIXELS 16
- #define Max 885 //浮子自然位置adc
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);//初始化RGB库文件
- int delayval = 500; //设置延迟时间
-
- int pinInterrupt = 3; //为升级使用中断预留
-
- int Aver1;//adc采样 平均
- int Aver2;
- int Aver3;
- int Aver4;
- int Aver5;
- int Aver6;
- int Aver7;
-
- void setup() {
- Serial.begin(115200);
- printf_begin();
- pinMode(A0,INPUT);
- pinMode(A5,OUTPUT);
- strip.begin();
- strip.show();
-
- }
-
- void loop() {
- rainbow(6);
- //colorWipe(strip.Color(0, 255, 0), 1);
- attachInterrupt( digitalPinToInterrupt(pinInterrupt), onChange, CHANGE); //电平变化进入中断
- digitalWrite(A5,HIGH);
-
- Aver1=analogRead(A0);
- delay(5);
- Aver2=analogRead(A0);
- delay(5);
- Aver3=analogRead(A0); delay(5);
- Aver4=analogRead(A0); delay(5);
- Aver5=analogRead(A0); delay(5);
- Aver6=analogRead(A0); delay(5);
- Aver7=analogRead(A0); delay(5);
- int k= ( Aver1+ Aver2+ Aver3+ Aver4+ Aver5+ Aver6+ Aver7)/7;
-
- printf("%drn",k);
- int m=1;
- if(k<=Max)
- {
- digitalWrite(A5,LOW); delay(200);digitalWrite(A5,HIGH);
- colorWipe(strip.Color(255, 0, 0), 20);
- printf("Q");//输出电压值以及触发条件 调试时使用
- colorWipe(strip.Color(0, 255, 0), 1);
- while(m)
- {
- colorWipe(strip.Color(0, 255, 0), 1);
-
- //等待中断
-
-
- }
-
- }
-
-
- // 0以下是rgb一级串口重定向调试实现必要函数0000000000000000000000000000
-
- int serial_putc( char c, struct __file * )
- {
- Serial.write( c );
- return c;
- }
- void printf_begin(void)
- {
- fdevopen( &serial_putc, 0 );
- }
- void colorWipe(uint32_t c, uint8_t wait) {
- for(uint16_t i=0; i
- strip.setPixelColor(i, c);
- strip.show();
- delay(wait);
- }
- }
-
- void rainbow(uint8_t wait) {//彩虹RGB变化
- uint16_t i, j;
-
- for(j=0; j<256; j++) {
- for(i=0; i
- strip.setPixelColor(i, Wheel((i+j) & 255));
- }
- strip.show();
- delay(wait);
- }
- }
-
- void rainbowCycle(uint8_t wait) {//转轮式彩虹RGB变化
- uint16_t i, j;
-
- for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
- 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++) { //do 10 cycles of chasing
- for (int q=0; q < 3; q++) {
- for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
- strip.setPixelColor(i+q, c); //turn every third pixel on
- }
- strip.show();
-
- delay(wait);
-
- for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
- strip.setPixelColor(i+q, 0); //turn every third pixel off
- }
- }
- }
- }
-
-
- void theaterChaseRainbow(uint8_t wait) {
- for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
- for (int q=0; q < 3; q++) {
- for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
- strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
- }
- strip.show();
-
- delay(wait);
-
- for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
- strip.setPixelColor(i+q, 0); //turn every third pixel off
- }
- }
- }
- }
- uint32_t Wheel(byte WheelPos) {
- WheelPos = 255 - WheelPos;
- if(WheelPos < 85) {
- return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
- }
- if(WheelPos < 170) {
- WheelPos -= 85;
- return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
- }
- WheelPos -= 170;
- return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
- }
复制代码
最佳答案
|
|
2018-5-3 17:43:58
评论
举报
|
|
|