forked from PetoiCamp/OpenCat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a638d5b
commit 76a9a76
Showing
17 changed files
with
5,414 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
119 changes: 119 additions & 0 deletions
119
ModuleTests/setBluetoothParameter/setBluetoothParameter.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// validate the bluetooth module by sending AT commands and reading "+OK" | ||
// the basic test is setting the bluetooth pin to "0000" | ||
// use: sendAT(String atCMD, String parameter, int ledIndex) for other commands | ||
// the ledIndex will set the corresponding RGB LED. green indicates that the command gets a "+OK" response. | ||
|
||
// validation: plug in the bluetooth module and the LED should blink green | ||
|
||
#define BLUE_NAME "BITTLE" | ||
#define BLUE_PIN "0000" | ||
#define BLUE_CURRENT_BAUD 115200 | ||
#define BLUE_BAUD "8" //115200 | ||
|
||
#define NYBOARD | ||
//#define PROMINI | ||
|
||
#ifdef NYBOARD | ||
#include <Adafruit_NeoPixel.h> | ||
#define PIXEL_PIN 10 | ||
#define NUMPIXELS 7 | ||
Adafruit_NeoPixel pixels(NUMPIXELS, PIXEL_PIN, NEO_GRB + NEO_KHZ800); | ||
|
||
#elif defined PROMINI | ||
#define RED_LED 3 | ||
#define GREEN_LED 5 | ||
#define BLUE_LED 6 | ||
#endif | ||
//4:9600 | ||
//5:19200 | ||
//6:38400 | ||
//7:57600 | ||
//8:115200 | ||
//9:128000 | ||
|
||
#define BUZZER 5 | ||
#define LIT_ON 30 | ||
void beep(int note, float duration = 10, int pause = 0, byte repeat = 1 ) { | ||
if (note == 0) { | ||
analogWrite(BUZZER, 0); | ||
delay(duration); | ||
return; | ||
} | ||
int freq = 220 * pow(1.059463, note - 1); // 220 is note A3 | ||
//1.059463 comes from https://en.wikipedia.org/wiki/Twelfth_root_of_two | ||
float period = 1000000.0 / freq / 2.0; | ||
for (byte r = 0; r < repeat; r++) { | ||
for (float t = 0; t < duration * 1000; t += period * 2) { | ||
analogWrite(BUZZER, 150); // Almost any value can be used except 0 and 255. it can be tuned as the amplitude of the note | ||
// experiment to get the best tone | ||
delayMicroseconds(period); // wait for a delayms ms | ||
analogWrite(BUZZER, 0); // 0 turns it off | ||
delayMicroseconds(period); // wait for a delayms ms | ||
} | ||
delay(pause); | ||
} | ||
} | ||
void blinkColor(int led_pin) { | ||
analogWrite(led_pin, LIT_ON); | ||
delay(50); | ||
analogWrite(led_pin, 0); | ||
//delay(2); | ||
} | ||
void sendAT(String atCMD, String parameter, int ledIndex) { | ||
Serial.println(String("AT+") + atCMD + parameter); | ||
delay(2); | ||
String in = Serial.readString(); | ||
if (in.substring(0, 3) == "+OK") { | ||
#ifdef NYBOARD | ||
beep(10, 3); | ||
pixels.setPixelColor(ledIndex, pixels.Color( 0, LIT_ON, 0)); | ||
#elif defined PROMINI | ||
blinkColor(GREEN_LED); | ||
#endif | ||
} | ||
else { | ||
#ifdef NYBOARD | ||
beep(14, 10, 10, in.length()); | ||
pixels.setPixelColor(ledIndex, pixels.Color(LIT_ON, 0, 0)); | ||
#elif defined PROMINI | ||
blinkColor(RED_LED); | ||
#endif | ||
} | ||
#ifdef NYBOARD | ||
pixels.show(); // Send the updated pixel colors to the hardware. | ||
#endif | ||
} | ||
|
||
void setup() { | ||
#ifdef NYBOARD | ||
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) | ||
pixels.clear(); // Set all pixel colors to 'off' | ||
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255 | ||
pixels.setPixelColor(0, pixels.Color(0, 0, LIT_ON)); | ||
pixels.show(); // Send the updated pixel colors to the hardware. | ||
pinMode(BUZZER, OUTPUT); | ||
beep(4); | ||
#elif defined PROMINI | ||
pinMode(RED_LED, OUTPUT); | ||
pinMode(GREEN_LED, OUTPUT); | ||
pinMode(BLUE_LED, OUTPUT); | ||
blinkColor(BLUE_LED); | ||
#endif | ||
Serial.begin(BLUE_CURRENT_BAUD); | ||
randomSeed(analogRead(A7));//use the fluctuation of voltage caused by servos as entropy pool | ||
|
||
} | ||
|
||
void loop() { | ||
// put your main code here, to run repeatedly: | ||
#ifdef NYBOARD | ||
pixels.setPixelColor(1, pixels.Color(0, 0, 0)); | ||
//pixels.setPixelColor(2, pixels.Color(0, 0, 0)); | ||
//pixels.setPixelColor(3, pixels.Color(0, 0, 0)); | ||
pixels.show(); // Send the updated pixel colors to the hardware. | ||
#endif | ||
while (Serial.available() && Serial.read());//flush serial buffer | ||
sendAT("PIN", String(BLUE_PIN), 1); | ||
//sendAT("NAME", String(BLUE_NAME) + String(random(10000)), 2); | ||
//sendAT("BAUD", BLUE_BAUD, 3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* Customized note and melody player for OpenCat, and MEOW \(=^_^=)/ | ||
It also serves to test the baud rate of the serial moniter and the crystal frequency. | ||
OpenCat happens to use 57600 baud rate (and a 20MHz crystal on Petoi's dedicated PCB). | ||
If you cannot see this sentence on serial monitor, | ||
there's something wrong with your Arduino IDE's configuration. | ||
The beep() is better if played with a passive buzzer | ||
The meow() can only be played with an active buzzer on PWM pins | ||
On most Arduino, the PWM pins are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11. | ||
If your buzzer cannot meow(), it's probably a passive buzzer. | ||
Rongzhong Li | ||
August 2017 | ||
Copyright (c) 2018 Petoi LLC. | ||
The MIT License | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
#define BUZZER 5 // the PWM pin the ACTIVE buzzer is attached to | ||
int loopCounter = 0; | ||
// tone 1 corresponds to A3, tone 2 corresponds to B3, tone 13 corresponds to A4, etc. | ||
// tone: pause,1, 2, 3, 4, 5, 6, 7, high1, high2 | ||
// code: 0, 1, 3, 5, 6, 8, 10, 12, 13, 15 | ||
byte melody[] = {8, 13, 10, 13, 8, 0, 5, 8, 3, 5, 8,//tone | ||
8, 8, 32, 32, 8, 32, 32, 32, 32, 32, 8 //relative duration, 8 means 1/8 note length | ||
}; | ||
|
||
void beep(int note, float duration = 10, int pause = 0, byte repeat = 1 ) { | ||
if (note == 0) { | ||
analogWrite(BUZZER, 0); | ||
delay(duration); | ||
return; | ||
} | ||
int freq = 220 * pow(1.059463, note - 1); // 220 is note A3 | ||
//1.059463 comes from https://en.wikipedia.org/wiki/Twelfth_root_of_two | ||
float period = 1000000.0 / freq / 2.0; | ||
for (byte r = 0; r < repeat; r++) { | ||
for (float t = 0; t < duration * 1000; t += period * 2) { | ||
analogWrite(BUZZER, 150); // Almost any value can be used except 0 and 255. it can be tuned as the amplitude of the note | ||
// experiment to get the best tone | ||
delayMicroseconds(period); // wait for a delayms ms | ||
analogWrite(BUZZER, 0); // 0 turns it off | ||
delayMicroseconds(period); // wait for a delayms ms | ||
} | ||
delay(pause); | ||
} | ||
} | ||
void playMelody(byte m[], int len) { | ||
for (int i = 0; i < len; i++) | ||
beep(m[i], 1000 / m[len + i], 100); | ||
} | ||
|
||
void meow(int repeat = 1, int pause = 200, int startF = 150, int endF = 255, int increment = 5) { | ||
for (int r = 0; r < repeat; r++) { | ||
for (int amp = startF; amp <= endF; amp += increment) { | ||
analogWrite(BUZZER, amp); | ||
delay(30); // wait for 30 milliseconds to allow the buzzer to vibrate | ||
} | ||
delay(500); | ||
analogWrite(BUZZER, 0); | ||
delay(pause); | ||
} | ||
} | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
pinMode(BUZZER, OUTPUT); | ||
Serial.println("if (you cannot see this sentence on serial monitor)"); | ||
Serial.println("\tthere's something wrong with your Arduino IDE's configuration."); | ||
} | ||
|
||
void loop() { | ||
if (loopCounter == 0) { | ||
beep(1, 500, 500); | ||
beep(13, 500, 500); | ||
playMelody(melody, sizeof(melody) / 2); | ||
Serial.println(loopCounter++); | ||
delay(1000); | ||
} | ||
else if (loopCounter < 2) { | ||
meow(1, 1000, 100); | ||
meow(2, 100); | ||
Serial.println(loopCounter++); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// -------------------------------------- | ||
// i2c_scanner | ||
// | ||
// Version 1 | ||
// This program (or code that looks like it) | ||
// can be found in many places. | ||
// For example on the Arduino.cc forum. | ||
// The original author is not know. | ||
// Version 2, Juni 2012, Using Arduino 1.0.1 | ||
// Adapted to be as simple as possible by Arduino.cc user Krodal | ||
// Version 3, Feb 26 2013 | ||
// V3 by louarnold | ||
// Version 4, March 3, 2013, Using Arduino 1.0.3 | ||
// by Arduino.cc user Krodal. | ||
// Changes by louarnold removed. | ||
// Scanning addresses changed from 0...127 to 1...119, | ||
// according to the i2c scanner by Nick Gammon | ||
// http://www.gammon.com.au/forum/?id=10896 | ||
// Version 5, March 28, 2013 | ||
// As version 4, but address scans now to 127. | ||
// A sensor seems to use address 120. | ||
// Version 6, November 27, 2015. | ||
// Added waiting for the Leonardo serial communication. | ||
// | ||
// | ||
// This sketch tests the standard 7-bit addresses | ||
// Devices with higher bit address might not be seen properly. | ||
// | ||
|
||
#include <Wire.h> | ||
|
||
|
||
void setup() | ||
{ | ||
Wire.begin(); | ||
|
||
Serial.begin(115200); | ||
while (!Serial); // Leonardo: wait for serial monitor | ||
Serial.println("\nI2C Scanner"); | ||
} | ||
|
||
|
||
void loop() | ||
{ | ||
byte error, address; | ||
int nDevices; | ||
|
||
Serial.println("Scanning..."); | ||
|
||
nDevices = 0; | ||
for(address = 1; address < 127; address++ ) | ||
{ | ||
// The i2c_scanner uses the return value of | ||
// the Write.endTransmisstion to see if | ||
// a device did acknowledge to the address. | ||
Wire.beginTransmission(address); | ||
error = Wire.endTransmission(); | ||
|
||
if (error == 0) | ||
{ | ||
Serial.print("I2C device found at address 0x"); | ||
if (address<16) | ||
Serial.print("0"); | ||
Serial.print(address,HEX); | ||
Serial.println(" !"); | ||
|
||
nDevices++; | ||
} | ||
else if (error==4) | ||
{ | ||
Serial.print("Unknown error at address 0x"); | ||
if (address<16) | ||
Serial.print("0"); | ||
Serial.println(address,HEX); | ||
} | ||
} | ||
if (nDevices == 0) | ||
Serial.println("No I2C devices found\n"); | ||
else | ||
Serial.println("done\n"); | ||
|
||
delay(5000); // wait 5 seconds for next scan | ||
} |
Oops, something went wrong.