PCB图如下:
描述
BT智能手机探测器
一个简单的 USB 设备,当通电时会检测您的智能手机。如果未检测到,则发出蜂鸣声。用作车上的提醒,因为我经常在家或办公室忘记电话;)
代码
ATTINY85 芯片的 Arduino 代码
C/C++
/* | |
1 (PB5) -- (Vcc) 8 | |
2 (PB3) -- (PB2) 7 | |
3 (PB4) -- (PB1) 6 | |
4 (GND) -- (PB0) 5 | |
PB5 -> 10 | |
PB0 -> 11 | |
PB1 -> 12 | |
PB2 -> 13 | |
REV. 2-7-2019 | |
*/ | |
#include |
|
#include |
|
//#include |
|
//SoftwareSerial Monitor(5, 4); | |
#define POWER 3//pin 2 - used to turn-on the BT module | |
#define BUZZER 1 //pin 6 | |
#define PULSE_IN 2 //pin 7 | |
int duration = 0; | |
void setup() { | |
pinMode(BUZZER, OUTPUT); | |
pinMode(POWER, OUTPUT); | |
pinMode(PULSE_IN, INPUT); | |
// used for serial | |
/*pinMode(0, OUTPUT); | |
pinMode(4, OUTPUT); // --> TX | |
pinMode(5, INPUT);// --> RX | |
Monitor.begin(9600); | |
*/ | |
digitalWrite(POWER, HIGH); | |
digitalWrite (BUZZER, HIGH); | |
//wait fot BT to come up | |
delay(20000); | |
} | |
void loop() { | |
duration = pulseIn(PULSE_IN, LOW) / 100; | |
if (duration >0) { | |
for (int i = 0; i < 30; i++) { | |
beep(500, 100); | |
} | |
//turn off BT | |
digitalWrite(POWER, LOW); | |
pinMode(POWER, INPUT); | |
sleep(); | |
} | |
else { | |
//turn off BT | |
digitalWrite(POWER, LOW); | |
pinMode(POWER, INPUT); | |
sleep(); | |
} | |
} | |
void beep(unsigned char delay_ms, unsigned char duration) { | |
analogWrite(BUZZER, duration);// Almost any value can be used except 0 and 255 | |
// experiment to get the best tone | |
delay(delay_ms);// wait for a delay ms | |
analogWrite(BUZZER, 0); // 0 turns it off | |
delay(delay_ms);// wait for a delay ms | |
} | |
void sleep() { | |
set_sleep_mode(SLEEP_MODE_PWR_DOWN); | |
ADCSRA = 0;// ADC off | |
power_all_disable(); | |
sleep_enable(); | |
sleep_cpu();// sleep | |
} |
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
全部0条评论
快来发表一下你的评论吧 !