8334浏览
查看: 8334|回复: 13

炫书包

[复制链接]
小学毕业的儿子准备上中学了,自己搜索选购了一 款“我的世界“夜光书包。

受其发光警示作用的激发~夜路更安全,我决定用LED灯带和传感器给它添点炫酷效果。


炫书包图4


【简单功能】

1.根据环境光强自动决定开关炫彩(随机七种)灯光

2.蜂鸣声音提示背后7米左右有人尾随

3.触摸开关可切换关闭蜂鸣提示



【材料清单】

6.UNO+IO传感器扩展板【实验用方便】
7.Cheapduino控制器【书包用简洁】
8.电源、开关、线材

【信号线针脚图】
炫书包图1  


【盖住环境光传感器模拟黑夜】
炫书包图2




Arduino 代码】
注:书包上的控制器最好选CheapDuino,小巧,低功耗,可用旧手机电池(3.7~4.2V)
炫书包图3
[mw_shl_code=cpp,true]
#include <Adafruit_NeoPixel.h>
#define BUZZER_PIN   A0   
#define AmbientLight_PIN   A5
#define TOUCH_PIN   10                                                                              
#define PIXEL_PIN    9   
#define PIR_PIN      11  

// Parameter 1 = number of pixels in strip,  neopixel stick has 8
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream
//   NEO_GRB     Pixels are wired for GRB bitstream, correct for neopixel stick
//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

bool oldTouch = LOW;
bool newTouch = LOW;
bool touchState = 0;
///////////////////////////////////////////////////////
void setup() {  
  pinMode(AmbientLight_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(PIR_PIN, INPUT);
  pinMode(TOUCH_PIN, INPUT_PULLUP);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}
///////////////////////////////////////////////////////
void loop() {
  // Get current button state.
  int ambLight = analogRead(AmbientLight_PIN);
  bool newTouch = digitalRead(TOUCH_PIN);
  bool pirYes = digitalRead(PIR_PIN);
  // Check if state changed from high to low (button press).
  if( ambLight < 5 ){
         if( (oldTouch == LOW) && (newTouch == HIGH )){
              touchState = 1 - touchState;
              delay(25);
         }
         
         if(touchState == 1)
             startShow(random(8));
         else if(pirYes == HIGH){
             startShow( 7 ); // Red
             buzzerAlarm();
         }else
            startShow(random(8));         
  }
      // Set the last button touchState to the old state.
   oldTouch = newTouch;
} // end ambLight
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////

void startShow(int i) {
  switch(i){
    case 0: colorWipe(strip.Color(0, 0, 0), 20);    // Black/off
            break;
   case 1: colorWipe(strip.Color(0, 0, 0), 20);    // Black/off
           colorWipe(strip.Color(255, 0, 0), 20);  // Red
          break;
    case 2: colorWipe(strip.Color(0, 0, 0), 20);    // Black/off
            colorWipe(strip.Color(0, 255, 0), 20);  // Green
            break;
    case 3: colorWipe(strip.Color(0, 0, 0), 20);    // Black/off
            colorWipe(strip.Color(0, 0, 255), 20);  // Blue
            break;
    case 4: colorWipe(strip.Color(0, 0, 0), 20);    // Black/off
            theaterChase(strip.Color(127, 127, 127), 20);  // white
            break;
    case 5: colorWipe(strip.Color(0, 0, 0), 20);    // Black/off
            rainbow(10);
            break;
    case 6: colorWipe(strip.Color(0, 0, 0), 20);    // Black/off
            rainbowCycle(1);
            break;
    case 7: colorWipe(strip.Color(0, 0, 0), 20);    // Black/off
            for(int i=0;i<5;i++){
                colorWipe(strip.Color(255,   0,   0), 10); // Red
                colorWipe(strip.Color(0, 0, 0), 10);    // Black/off
            }
            break;
  }
}
////////////////////////////////////
void buzzerAlarm(){
            for(int i=0;i<80;i++){  // Buzzer start
              digitalWrite(BUZZER_PIN, HIGH);
              delay(1);
              digitalWrite(BUZZER_PIN, LOW);
              delay(1);  
            }
           for(int i=0;i<100;i++){
              digitalWrite(BUZZER_PIN, HIGH);
              delay(2);
              digitalWrite(BUZZER_PIN, LOW);
              delay(2);  
           }
}  // Buzzer end
///////////////////////////////////////////////////////
// Fill the dots one after the other with a color
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);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  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);
  }
}

//Theatre-style crawling lights.
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 (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

//Theatre-style crawling lights with rainbow effect
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 (int 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 (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
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);
}[/mw_shl_code]



1503722232117.gif

hnyzcj  版主

发表于 2017-8-27 10:59:41

赞一个,很漂亮,哈哈哈
回复

使用道具 举报

pATAq  版主

发表于 2017-8-28 16:31:25

这个不错,七夕到了可以哄小姑娘
回复

使用道具 举报

安卓机器人  中级技神
 楼主|
来自手机

发表于 2017-8-29 09:01:21

pATAq 发表于 2017-8-28 16:31
这个不错,七夕到了可以哄小姑娘

嗯,炫手环...
回复

使用道具 举报

安卓机器人  中级技神
 楼主|
来自手机

发表于 2017-8-29 09:04:08

hnyzcj 发表于 2017-8-27 10:59
赞一个,很漂亮,哈哈哈

蟹蟹鼓励
回复

使用道具 举报

xar  初级技匠

发表于 2017-9-16 19:48:40

晚自习回家回头率一定高高
回复

使用道具 举报

senghu  初级技师

发表于 2017-9-26 12:10:18

很不错的IDEA
回复

使用道具 举报

snake  见习技师

发表于 2018-1-5 13:22:45

赞赞赞赞
回复

使用道具 举报

赤星三春牛!  初级技神

发表于 2022-2-3 13:59:11

哇哇哇哇哇哇哇哇哇哇
回复

使用道具 举报

赤星三春牛!  初级技神

发表于 2022-2-3 13:59:34

赞赞赞赞赞赞赞赞赞赞赞赞赞赞赞赞
回复

使用道具 举报

赤星三春牛!  初级技神

发表于 2022-2-3 13:59:56

很不错!      
回复

使用道具 举报

赤星三春牛!  初级技神

发表于 2022-2-3 14:00:13

666666666666
回复

使用道具 举报

安卓机器人  中级技神
 楼主|

发表于 2022-2-5 16:40:22


哈哈哈哈哈哈,积分
回复

使用道具 举报

温暖的蓝色  中级技师

发表于 2022-2-16 00:21:16

你须十分努力,才能看起来毫不费力
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail