mirror of
https://github.com/KevinMidboe/Arduino.git
synced 2025-10-29 09:30:12 +00:00
Init commit with many years of arduino sketches and projects. I dont know if the esp8266 includes much, but there are also libraries. I hope they dont have crazy automatic versioning through the Arduino IDE.
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
|
||||
int leftCCW[] = {8, 9, 10, 11};
|
||||
int leftCW[] = {11, 10, 9, 8};
|
||||
int leftButtons[] = {2, 3};
|
||||
|
||||
int rightCCW[] = {4, 5, 6, 7};
|
||||
int rightCW[] = {7, 6, 5, 4};
|
||||
int rightButtons[] = {0, 1};
|
||||
|
||||
const int motorSteps[8][4] = {
|
||||
{1, 0, 0, 0},
|
||||
{1, 1, 0, 0},
|
||||
{0, 1, 0, 0},
|
||||
{0, 1, 1, 0},
|
||||
{0, 0, 0, 1},
|
||||
{0, 0, 1, 1},
|
||||
{0, 0, 0, 1},
|
||||
{1, 0, 0, 1}
|
||||
};
|
||||
|
||||
int motorSpeed = 0;
|
||||
|
||||
void setup() {
|
||||
for (int i=0; i < 4; i++) {
|
||||
pinMode(leftCW[i], OUTPUT);
|
||||
pinMode(rightCW[i], OUTPUT);
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
pinMode(leftButtons[i], INPUT);
|
||||
pinMode(rightButtons[i], INPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (analogRead(leftButtons[0]) == 0) {
|
||||
leftUp();
|
||||
} else if(analogRead(leftButtons[1]) == 1){
|
||||
leftDown();
|
||||
}
|
||||
|
||||
if (analogRead(leftButtons[0]) == 0) {
|
||||
rightUp();
|
||||
} else if(analogRead(leftButtons[1]) == 1){
|
||||
rightDown();
|
||||
}
|
||||
}
|
||||
|
||||
void leftUp() {
|
||||
for(int i=0; i < 8; i++){
|
||||
for(int j=0; j < 4; j++){
|
||||
// Left motor
|
||||
digitalWrite(leftCW[j], motorSteps[j][i]);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void leftDown() {
|
||||
for(int i=0; i < 8; i++){
|
||||
for(int j=0; j < 4; j++){
|
||||
// Left motor
|
||||
digitalWrite(leftCCW[j], motorSteps[j][i]);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rightUp() {
|
||||
for(int i=0; i < 8; i++){
|
||||
for(int j=0; j < 4; j++){
|
||||
// Right motor
|
||||
digitalWrite(rightCCW[j], motorSteps[j][i]);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rightDown() {
|
||||
for(int i=0; i < 8; i++){
|
||||
for(int j=0; j < 4; j++){
|
||||
// Right motor
|
||||
digitalWrite(rightCW[j], motorSteps[j][i]);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
166
Projects/28BYJ Stepper/first_test/first_test.ino
Normal file
166
Projects/28BYJ Stepper/first_test/first_test.ino
Normal file
@@ -0,0 +1,166 @@
|
||||
// This Arduino example demonstrates bidirectional operation of a
|
||||
// 28BYJ-48, which is readily available on eBay, using a ULN2003
|
||||
// interface board to drive the stepper. The 28BYJ-48 motor is a 4-
|
||||
// phase, 8-beat motor, geared down by a factor of 68. Onint e bipolar
|
||||
// winding is on motor pins 1 & 3 and the other on motor pins 2 & 4.
|
||||
// Refer to the manufacturer's documentation of Changzhou Fulling
|
||||
// Motor Co., Ltd., among others. The step angle is 5.625/64 and the
|
||||
// operating Frequency is 100pps. Current draw is 92mA. In this
|
||||
// example, the speed and direction of the stepper motor is determined
|
||||
// by adjusting a 1k-ohm potentiometer connected to Arduino pin A2.
|
||||
// When the potentiometer is rotated fully counterclockwise, the motor
|
||||
// will rotate at full counterclockwise speed. As the potentiometer is
|
||||
// rotated clockwise, the motor will continue to slow down until is
|
||||
// reaches its minimum speed at the the potentiometer's midpoint value .
|
||||
// Once the potentiometer crosses its midpoint, the motor will reverse
|
||||
// direction. As the potentiometer is rotated further clockwise, the speed
|
||||
// of the motor will increase until it reaches its full clockwise rotation
|
||||
// speed when the potentiometer has been rotated fully clockwise.
|
||||
////////////////////////////////////////////////
|
||||
|
||||
//declare variables for the motor pins
|
||||
int motorPin1 = 8; // Blue - 28BYJ48 pin 1
|
||||
int motorPin2 = 9; // Pink - 28BYJ48 pin 2
|
||||
int motorPin3 = 10; // Yellow - 28BYJ48 pin 3
|
||||
int motorPin4 = 11; // Orange - 28BYJ48 pin 4
|
||||
// Red - 28BYJ48 pin 5 (VCC)
|
||||
|
||||
int motorSpeed = 0; //variable to set stepper speed
|
||||
int potPin = 2; //potentiometer connected to A2
|
||||
int potValue = 0; //variable to read A0 input
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void setup() {
|
||||
//declare the motor pins as outputs
|
||||
pinMode(motorPin1, OUTPUT);
|
||||
pinMode(motorPin2, OUTPUT);
|
||||
pinMode(motorPin3, OUTPUT);
|
||||
pinMode(motorPin4, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void loop(){
|
||||
|
||||
//potValue = analogRead(potPin); // read the value of the potentiometer
|
||||
Serial.println(potValue); // View full range from 0 - 1024 in Serial Monitor
|
||||
if (potValue < 535){ // if potentiometer reads 0 to 535 do this
|
||||
motorSpeed = (potValue/15 + 5); //scale potValue to be useful for motor
|
||||
clockwise(); //go to the ccw rotation function
|
||||
}
|
||||
else { //value of the potentiometer is 512 - 1024
|
||||
motorSpeed = ((1024-potValue)/15 + 5); //scale potValue for motor speed
|
||||
counterclockwise(); //go the the cw rotation function
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//set pins to ULN2003 high in sequence from 1 to 4
|
||||
//delay "motorSpeed" between each pin setting (to determine speed)
|
||||
|
||||
void counterclockwise (){
|
||||
// 1
|
||||
digitalWrite(motorPin1, HIGH);
|
||||
digitalWrite(motorPin2, LOW);
|
||||
digitalWrite(motorPin3, LOW);
|
||||
digitalWrite(motorPin4, LOW);
|
||||
delay(motorSpeed);
|
||||
// 2
|
||||
digitalWrite(motorPin1, HIGH);
|
||||
digitalWrite(motorPin2, HIGH);
|
||||
digitalWrite(motorPin3, LOW);
|
||||
digitalWrite(motorPin4, LOW);
|
||||
delay (motorSpeed);
|
||||
// 3
|
||||
digitalWrite(motorPin1, LOW);
|
||||
digitalWrite(motorPin2, HIGH);
|
||||
digitalWrite(motorPin3, LOW);
|
||||
digitalWrite(motorPin4, LOW);
|
||||
delay(motorSpeed);
|
||||
// 4
|
||||
digitalWrite(motorPin1, LOW);
|
||||
digitalWrite(motorPin2, HIGH);
|
||||
digitalWrite(motorPin3, HIGH);
|
||||
digitalWrite(motorPin4, LOW);
|
||||
delay(motorSpeed);
|
||||
// 5
|
||||
digitalWrite(motorPin1, LOW);
|
||||
digitalWrite(motorPin2, LOW);
|
||||
digitalWrite(motorPin3, HIGH);
|
||||
digitalWrite(motorPin4, LOW);
|
||||
delay(motorSpeed);
|
||||
// 6
|
||||
digitalWrite(motorPin1, LOW);
|
||||
digitalWrite(motorPin2, LOW);
|
||||
digitalWrite(motorPin3, HIGH);
|
||||
digitalWrite(motorPin4, HIGH);
|
||||
delay (motorSpeed);
|
||||
// 7
|
||||
digitalWrite(motorPin1, LOW);
|
||||
digitalWrite(motorPin2, LOW);
|
||||
digitalWrite(motorPin3, LOW);
|
||||
digitalWrite(motorPin4, HIGH);
|
||||
delay(motorSpeed);
|
||||
// 8
|
||||
digitalWrite(motorPin1, HIGH);
|
||||
digitalWrite(motorPin2, LOW);
|
||||
digitalWrite(motorPin3, LOW);
|
||||
digitalWrite(motorPin4, HIGH);
|
||||
delay(motorSpeed);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//set pins to ULN2003 high in sequence from 4 to 1
|
||||
//delay "motorSpeed" between each pin setting (to determine speed)
|
||||
|
||||
void clockwise(){
|
||||
// 1
|
||||
digitalWrite(motorPin4, HIGH);
|
||||
digitalWrite(motorPin3, LOW);
|
||||
digitalWrite(motorPin2, LOW);
|
||||
digitalWrite(motorPin1, LOW);
|
||||
delay(motorSpeed);
|
||||
// 2
|
||||
digitalWrite(motorPin4, HIGH);
|
||||
digitalWrite(motorPin3, HIGH);
|
||||
digitalWrite(motorPin2, LOW);
|
||||
digitalWrite(motorPin1, LOW);
|
||||
delay (motorSpeed);
|
||||
// 3
|
||||
digitalWrite(motorPin4, LOW);
|
||||
digitalWrite(motorPin3, HIGH);
|
||||
digitalWrite(motorPin2, LOW);
|
||||
digitalWrite(motorPin1, LOW);
|
||||
delay(motorSpeed);
|
||||
// 4
|
||||
digitalWrite(motorPin4, LOW);
|
||||
digitalWrite(motorPin3, HIGH);
|
||||
digitalWrite(motorPin2, HIGH);
|
||||
digitalWrite(motorPin1, LOW);
|
||||
delay(motorSpeed);
|
||||
// 5
|
||||
digitalWrite(motorPin4, LOW);
|
||||
digitalWrite(motorPin3, LOW);
|
||||
digitalWrite(motorPin2, HIGH);
|
||||
digitalWrite(motorPin1, LOW);
|
||||
delay(motorSpeed);
|
||||
// 6
|
||||
digitalWrite(motorPin4, LOW);
|
||||
digitalWrite(motorPin3, LOW);
|
||||
digitalWrite(motorPin2, HIGH);
|
||||
digitalWrite(motorPin1, HIGH);
|
||||
delay (motorSpeed);
|
||||
// 7
|
||||
digitalWrite(motorPin4, LOW);
|
||||
digitalWrite(motorPin3, LOW);
|
||||
digitalWrite(motorPin2, LOW);
|
||||
digitalWrite(motorPin1, HIGH);
|
||||
delay(motorSpeed);
|
||||
// 8
|
||||
digitalWrite(motorPin4, HIGH);
|
||||
digitalWrite(motorPin3, LOW);
|
||||
digitalWrite(motorPin2, LOW);
|
||||
digitalWrite(motorPin1, HIGH);
|
||||
delay(motorSpeed);
|
||||
}
|
||||
95
Projects/28BYJ Stepper/second/second.ino
Normal file
95
Projects/28BYJ Stepper/second/second.ino
Normal file
@@ -0,0 +1,95 @@
|
||||
|
||||
int leftCCW[] = {8, 9, 10, 11};
|
||||
int leftCW[] = {11, 10, 9, 8};
|
||||
int leftButtons[] = {0, 1};
|
||||
|
||||
int rightCCW[] = {4, 5, 6, 7};
|
||||
int rightCW[] = {7, 6, 5, 4};
|
||||
int rightButtons[] = {2, 3};
|
||||
|
||||
const int motorSteps[8][4] = {
|
||||
{1, 0, 0, 0},
|
||||
{1, 1, 0, 0},
|
||||
{0, 1, 0, 0},
|
||||
{0, 1, 1, 0},
|
||||
{0, 0, 0, 1},
|
||||
{0, 0, 1, 1},
|
||||
{0, 0, 0, 1},
|
||||
{1, 0, 0, 1}
|
||||
};
|
||||
|
||||
int motorSpeed = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
for (int i=0; i < 4; i++) {
|
||||
pinMode(leftCW[i], OUTPUT);
|
||||
pinMode(rightCW[i], OUTPUT);
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
pinMode(leftButtons[i], INPUT);
|
||||
pinMode(rightButtons[i], INPUT);
|
||||
}
|
||||
|
||||
pinMode(12, INPUT);
|
||||
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (digitalRead(12) == LOW)
|
||||
{ windUp(); }
|
||||
else { windDown(); }
|
||||
}
|
||||
|
||||
void windUp() {
|
||||
while(digitalRead(rightButtons[1]) == LOW || digitalRead(leftButtons[1] == LOW)){
|
||||
if (digitalRead(rightButtons[1] == LOW))
|
||||
{
|
||||
for(int i=0; i < 8; i++){
|
||||
for(int j=0; j < 4; j++){
|
||||
// Right motor
|
||||
digitalWrite(rightCCW[j], motorSteps[j][i]);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (digitalRead(leftButtons[1] == LOW))
|
||||
{
|
||||
for(int i=0; i < 8; i++){
|
||||
for(int j=0; j < 4; j++){
|
||||
// Left motor
|
||||
digitalWrite(leftCW[j], motorSteps[j][i]);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void windDown() {
|
||||
while(digitalRead(rightButtons[0]) == LOW || digitalRead(leftButtons[0] == LOW)){
|
||||
if (digitalRead(rightButtons[0] == LOW)) {
|
||||
for(int i=0; i < 8; i++){
|
||||
for(int j=0; j < 4; j++){
|
||||
// Right motor
|
||||
digitalWrite(rightCW[j], motorSteps[j][i]);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (digitalRead(leftButtons[0] == LOW)) {
|
||||
for(int i=0; i < 8; i++){
|
||||
for(int j=0; j < 4; j++){
|
||||
// Left motor
|
||||
digitalWrite(leftCCW[j], motorSteps[j][i]);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
477
Projects/7 Segment Main/The_Final_Coutdown_/The_Final_Coutdown_.ino
Executable file
477
Projects/7 Segment Main/The_Final_Coutdown_/The_Final_Coutdown_.ino
Executable file
@@ -0,0 +1,477 @@
|
||||
/* ---------------------------------------------------------
|
||||
* | Arduino Experimentation Kit Example Code |
|
||||
* | CIRC-05 .: 8 More LEDs :. (74HC595 Shift Register) |
|
||||
* ---------------------------------------------------------
|
||||
*
|
||||
* We have already controlled 8 LEDs however this does it in a slightly
|
||||
* different manner. Rather than using 8 pins we will use just three
|
||||
* and an additional chip.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
//Pin Definitions
|
||||
//Pin Definitions
|
||||
//The 74HC595 uses a serial communication
|
||||
//link which has three pins
|
||||
int data = 11;
|
||||
int clock = 13;
|
||||
int latch = 12;
|
||||
|
||||
//Used for single LED manipulation
|
||||
int ledState = 0;
|
||||
const int ON = HIGH;
|
||||
const int OFF = LOW;
|
||||
|
||||
|
||||
int ledDigitalOne[] = {10, 9, 8, 7, 6, 5, 4}; //the three digital pins of the digital LED
|
||||
//9 = redPin, 10 = greenPin, 11 = bluePin
|
||||
//Predefined Colors
|
||||
|
||||
const boolean One[] = {ON, OFF, OFF, OFF, OFF, OFF, ON};
|
||||
const boolean Two[] = {OFF, ON, ON, ON, OFF, ON, ON};
|
||||
const boolean Three[] = {ON, ON, OFF, ON, OFF, ON, ON};
|
||||
const boolean Four[] = {ON, OFF, OFF, ON, ON, OFF, ON};
|
||||
const boolean Five[] = {ON, ON, OFF, ON, ON, ON, OFF};
|
||||
const boolean Six[] = {ON, ON, ON, ON, ON, ON, OFF};
|
||||
const boolean Seven[] = {ON, OFF, OFF, OFF, OFF, ON, ON};
|
||||
const boolean Eight[] = {ON, ON, ON, ON, ON, ON, ON};
|
||||
const boolean Nine[] = {ON, ON, OFF, ON, ON, ON, ON};
|
||||
const boolean Zero[] = {ON, ON, ON, OFF, ON, ON, ON};
|
||||
|
||||
|
||||
//An Array that stores the predefined colors (allows us to later randomly display a color)
|
||||
const boolean* NUMBERS[] = {One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Zero};
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(data, OUTPUT);
|
||||
pinMode(clock, OUTPUT);
|
||||
pinMode(latch, OUTPUT);
|
||||
|
||||
|
||||
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
pinMode(ledDigitalOne[i], OUTPUT); //Set the three LED pins as outputs
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int delayTime = 500;
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
changeLED(0,ON); // - 9
|
||||
changeLED(1,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
setNumber(ledDigitalOne, Nine);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Eight);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Seven);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Six);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Five);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Four);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Three);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Two);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, One);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Zero);
|
||||
delay(1000);
|
||||
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 8
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
setNumber(ledDigitalOne, Nine);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Eight);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Seven);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Six);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Five);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Four);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Three);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Two);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, One);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Zero);
|
||||
delay(1000);
|
||||
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(3,ON); // - 7
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
setNumber(ledDigitalOne, Nine);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Eight);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Seven);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Six);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Five);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Four);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Three);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Two);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, One);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Zero);
|
||||
delay(1000);
|
||||
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 6
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
setNumber(ledDigitalOne, Nine);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Eight);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Seven);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Six);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Five);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Four);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Three);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Two);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, One);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Zero);
|
||||
delay(1000);
|
||||
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 5
|
||||
changeLED(1,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
setNumber(ledDigitalOne, Nine);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Eight);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Seven);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Six);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Five);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Four);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Three);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Two);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, One);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Zero);
|
||||
delay(1000);
|
||||
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 4
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(6,ON);
|
||||
setNumber(ledDigitalOne, Nine);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Eight);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Seven);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Six);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Five);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Four);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Three);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Two);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, One);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Zero);
|
||||
delay(1000);
|
||||
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 3
|
||||
changeLED(1,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
setNumber(ledDigitalOne, Nine);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Eight);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Seven);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Six);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Five);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Four);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Three);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Two);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, One);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Zero);
|
||||
delay(1000);
|
||||
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - 2
|
||||
changeLED(2,ON);
|
||||
changeLED(0,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
setNumber(ledDigitalOne, Nine);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Eight);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Seven);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Six);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Five);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Four);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Three);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Two);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, One);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Zero);
|
||||
delay(1000);
|
||||
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(3,ON); // - 1
|
||||
changeLED(6,ON);
|
||||
setNumber(ledDigitalOne, Nine);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Eight);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Seven);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Six);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Five);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Four);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Three);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Two);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, One);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Zero);
|
||||
delay(1000);
|
||||
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(3,ON); // - 0
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
setNumber(ledDigitalOne, Nine);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Eight);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Seven);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Six);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Five);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Four);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Three);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Two);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, One);
|
||||
delay(1000);
|
||||
setNumber(ledDigitalOne, Zero);
|
||||
delay(1000);
|
||||
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* updateLEDs() - sends the LED states set in ledStates to the 74HC595
|
||||
* sequence
|
||||
*/
|
||||
void updateLEDs(int value){
|
||||
digitalWrite(latch, LOW); //Pulls the chips latch low
|
||||
shiftOut(data, clock, MSBFIRST, value); //Shifts out the 8 bits to the shift register
|
||||
digitalWrite(latch, HIGH); //Pulls the latch high displaying the data
|
||||
}
|
||||
|
||||
/*
|
||||
* updateLEDsLong() - sends the LED states set in ledStates to the 74HC595
|
||||
* sequence. Same as updateLEDs except the shifting out is done in software
|
||||
* so you can see what is happening.
|
||||
*/
|
||||
void updateLEDsLong(int value){
|
||||
digitalWrite(latch, LOW); //Pulls the chips latch low
|
||||
for(int i = 0; i < 8; i++){ //Will repeat 8 times (once for each bit)
|
||||
int bit = value & B10000000; //We use a "bitmask" to select only the eighth
|
||||
//bit in our number (the one we are addressing this time through
|
||||
value = value << 1; //we move our number up one bit value so next time bit 7 will be
|
||||
//bit 8 and we will do our math on it
|
||||
if(bit == 128){digitalWrite(data, HIGH);} //if bit 8 is set then set our data pin high
|
||||
else{digitalWrite(data, LOW);} //if bit 8 is unset then set the data pin low
|
||||
digitalWrite(clock, HIGH); //the next three lines pulse the clock pin
|
||||
delay(1);
|
||||
digitalWrite(clock, LOW);
|
||||
}
|
||||
digitalWrite(latch, HIGH); //pulls the latch high shifting our data into being displayed
|
||||
}
|
||||
|
||||
|
||||
//These are used in the bitwise math that we use to change individual LEDs
|
||||
//For more details http://en.wikipedia.org/wiki/Bitwise_operation
|
||||
int bits[] = {B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000};
|
||||
int masks[] = {B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111};
|
||||
/*
|
||||
* changeLED(int led, int state) - changes an individual LED
|
||||
* LEDs are 0 to 7 and state is either 0 - OFF or 1 - ON
|
||||
*/
|
||||
void changeLED(int led, int state){
|
||||
ledState = ledState & masks[led]; //clears ledState of the bit we are addressing
|
||||
if(state == ON){ledState = ledState | bits[led];} //if the bit is on we will add it to ledState
|
||||
updateLEDs(ledState); //send the new LED state to the shift register
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void setNumber(int* led, boolean* number)
|
||||
{
|
||||
for(int i = 0; i < 7; i++)
|
||||
{
|
||||
digitalWrite(led[i], number[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* A version of setColor that allows for using const boolean colors
|
||||
*/
|
||||
|
||||
void setNumber(int* led, const boolean* number)
|
||||
{
|
||||
boolean tempNumber[] = {number[0], number[1], number[2], number[3], number[4], number[5], number[6]};
|
||||
setNumber(led, tempNumber);
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
/* ---------------------------------------------------------
|
||||
* | Arduino Experimentation Kit Example Code |
|
||||
* | CIRC-05 .: 8 More LEDs :. (74HC595 Shift Register) |
|
||||
* ---------------------------------------------------------
|
||||
*
|
||||
* We have already controlled 8 LEDs however this does it in a slightly
|
||||
* different manner. Rather than using 8 pins we will use just three
|
||||
* and an additional chip.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
//Pin Definitions
|
||||
//Pin Definitions
|
||||
//The 74HC595 uses a serial communication
|
||||
//link which has three pins
|
||||
int data = 2;
|
||||
int clock = 3;
|
||||
int latch = 4;
|
||||
|
||||
//Used for single LED manipulation
|
||||
int ledState = 0;
|
||||
const int ON = HIGH;
|
||||
const int OFF = LOW;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int ledDigitalOne[] = {13, 12, 11, 10, 9, 8, 7, 6}; //the three digital pins of the digital LED
|
||||
//9 = redPin, 10 = greenPin, 11 = bluePin
|
||||
|
||||
const boolean ON1 = HIGH; //Define on as LOW (this is because we use a common
|
||||
//Anode RGB LED (common pin is connected to +5 volts)
|
||||
const boolean OFF1 = LOW; //Define off as HIGH
|
||||
|
||||
//Predefined Colors
|
||||
|
||||
const boolean One[] = {ON1, OFF1, OFF1, OFF1, OFF1, OFF1, ON1};
|
||||
const boolean Two[] = {OFF1, ON1, ON1, ON1, OFF1, ON1, ON1};
|
||||
const boolean Three[] = {ON1, ON1, OFF1, ON1, OFF1, ON1, ON1};
|
||||
const boolean Four[] = {ON1, OFF1, OFF1, ON1, ON1, OFF1, ON1};
|
||||
const boolean Five[] = {ON1, ON1, OFF1, ON1, ON1, ON1, OFF1};
|
||||
const boolean Six[] = {ON1, ON1, ON1, ON1, ON1, ON1, OFF1};
|
||||
const boolean Seven[] = {ON1, OFF1, OFF1, OFF1, OFF1, ON1, ON1};
|
||||
const boolean Eight[] = {ON1, ON1, ON1, ON1, ON1, ON1, ON1};
|
||||
const boolean Nine[] = {ON1, ON1, OFF1, ON1, ON1, ON1, ON1};
|
||||
const boolean Zero[] = {ON1, ON1, ON1, OFF1, ON1, ON1, ON1};
|
||||
|
||||
const boolean A[] = {OFF1, ON1, ON1, OFF1, ON1, ON1, OFF1};
|
||||
const boolean B[] = {ON1, ON1, ON1, OFF1, ON1, ON1, ON1};
|
||||
const boolean C[] = {ON1, ON1, OFF1, OFF1, OFF1, OFF1, ON1};
|
||||
const boolean D[] = {ON1, ON1, OFF1, ON1, OFF1, OFF1, OFF1};
|
||||
const boolean E[] = {ON1, ON1, ON1, OFF1, OFF1, OFF1, ON1};
|
||||
const boolean F[] = {OFF1, ON1, OFF1, OFF1, OFF1, OFF1, OFF1};
|
||||
const boolean G[] = {ON1, ON1, OFF1, OFF1, ON1, ON1, ON1};
|
||||
const boolean H[] = {OFF1, ON1, ON1, OFF1, ON1, ON1, OFF1};
|
||||
const boolean I[] = {OFF1, OFF1, OFF1, ON1, OFF1, OFF1, OFF1};
|
||||
const boolean J[] = {ON1, ON1, OFF1, OFF1, OFF1, ON1, ON1};
|
||||
const boolean K[] = {OFF1, ON1, ON1, ON1, OFF1, OFF1, ON1};
|
||||
const boolean L[] = {ON1, ON1, OFF1, OFF1, OFF1, OFF1, ON1};
|
||||
const boolean M[] = {OFF1, ON1, OFF1, OFF1, OFF1, ON1, OFF1};
|
||||
const boolean N[] = {OFF1, ON1, OFF1, ON1, OFF1, ON1, ON1};
|
||||
const boolean O[] = {ON1, ON1, OFF1, OFF1, OFF1, ON1, ON1};
|
||||
const boolean P[] = {OFF1, ON1, OFF1, OFF1, OFF1, OFF1, OFF1};
|
||||
const boolean Q[] = {ON1, ON1, OFF1, OFF1, OFF1, ON1, OFF1};
|
||||
const boolean R[] = {OFF1, ON1, OFF1, ON1, OFF1, OFF1, ON1};
|
||||
const boolean S[] = {ON1, OFF1, OFF1, OFF1, OFF1, ON1, ON1};
|
||||
const boolean T[] = {OFF1, OFF1, OFF1, ON1, OFF1, OFF1, OFF1};
|
||||
const boolean U[] = {ON1, ON1, OFF1, OFF1, OFF1, ON1, ON1};
|
||||
const boolean V[] = {OFF1, OFF1, OFF1, ON1, OFF1, OFF1, OFF1};
|
||||
const boolean W[] = {ON1, ON1, OFF1, ON1, OFF1, ON1, ON1};
|
||||
const boolean X[] = {OFF1, ON1, OFF1, OFF1, OFF1, ON1, OFF1};
|
||||
const boolean Y[] = {OFF1, OFF1, OFF1, ON1, OFF1, OFF1, OFF1};
|
||||
const boolean Z[] = {ON1, ON1, ON1, OFF1, OFF1, OFF1, ON1};
|
||||
const boolean EXCLA[] = {OFF1, ON1, OFF1, OFF1, OFF1, OFF1, OFF1, ON1};
|
||||
const boolean BLANK[] = {OFF1, OFF1, OFF1, OFF1, OFF1, OFF1, OFF1, OFF1};
|
||||
|
||||
|
||||
//An Array that stores the predefined colors (allows us to later randomly display a color)
|
||||
const boolean* NUMBERS[] = {One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Zero};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(data, OUTPUT);
|
||||
pinMode(clock, OUTPUT);
|
||||
pinMode(latch, OUTPUT);
|
||||
|
||||
|
||||
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
pinMode(ledDigitalOne[i], OUTPUT); //Set the three LED pins as outputs
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* loop() - this function will start after setup finishes and then repeat
|
||||
* we set which LEDs we want on then call a routine which sends the states to the 74HC595
|
||||
*/
|
||||
void loop() // run over and over again
|
||||
{
|
||||
int delayTime = 500;
|
||||
for (int i = 0; i < 31; i++)
|
||||
{
|
||||
changeLED(0,ON); // -- H
|
||||
changeLED(1,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, H);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // -- E
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
|
||||
setNumber(ledDigitalOne, E);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(3,ON); // - I
|
||||
|
||||
setNumber(ledDigitalOne, I);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
setNumber(ledDigitalOne, BLANK);
|
||||
delay(1000);
|
||||
|
||||
changeLED(0,ON); // -- E
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
|
||||
setNumber(ledDigitalOne, E);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - L
|
||||
|
||||
setNumber(ledDigitalOne, L);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(3,ON); // - I
|
||||
|
||||
setNumber(ledDigitalOne, I);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - A
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, A);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // -- S
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, S);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - EXCLA
|
||||
changeLED(7,ON);
|
||||
|
||||
setNumber(ledDigitalOne, EXCLA);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
changeLED(7,OFF);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* updateLEDs() - sends the LED states set in ledStates to the 74HC595
|
||||
* sequence
|
||||
*/
|
||||
void updateLEDs(int value){
|
||||
digitalWrite(latch, LOW); //Pulls the chips latch low
|
||||
shiftOut(data, clock, MSBFIRST, value); //Shifts out the 8 bits to the shift register
|
||||
digitalWrite(latch, HIGH); //Pulls the latch high displaying the data
|
||||
}
|
||||
|
||||
/*
|
||||
* updateLEDsLong() - sends the LED states set in ledStates to the 74HC595
|
||||
* sequence. Same as updateLEDs except the shifting out is done in software
|
||||
* so you can see what is happening.
|
||||
*/
|
||||
void updateLEDsLong(int value){
|
||||
digitalWrite(latch, LOW); //Pulls the chips latch low
|
||||
for(int i = 0; i < 8; i++){ //Will repeat 8 times (once for each bit)
|
||||
int bit = value & B10000000; //We use a "bitmask" to select only the eighth
|
||||
//bit in our number (the one we are addressing this time through
|
||||
value = value << 1; //we move our number up one bit value so next time bit 7 will be
|
||||
//bit 8 and we will do our math on it
|
||||
if(bit == 128){digitalWrite(data, HIGH);} //if bit 8 is set then set our data pin high
|
||||
else{digitalWrite(data, LOW);} //if bit 8 is unset then set the data pin low
|
||||
digitalWrite(clock, HIGH); //the next three lines pulse the clock pin
|
||||
delay(1);
|
||||
digitalWrite(clock, LOW);
|
||||
}
|
||||
digitalWrite(latch, HIGH); //pulls the latch high shifting our data into being displayed
|
||||
}
|
||||
|
||||
|
||||
//These are used in the bitwise math that we use to change individual LEDs
|
||||
//For more details http://en.wikipedia.org/wiki/Bitwise_operation
|
||||
int bits[] = {B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000};
|
||||
int masks[] = {B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111};
|
||||
/*
|
||||
* changeLED(int led, int state) - changes an individual LED
|
||||
* LEDs are 0 to 7 and state is either 0 - OFF or 1 - ON
|
||||
*/
|
||||
void changeLED(int led, int state){
|
||||
ledState = ledState & masks[led]; //clears ledState of the bit we are addressing
|
||||
if(state == ON){ledState = ledState | bits[led];} //if the bit is on we will add it to ledState
|
||||
updateLEDs(ledState); //send the new LED state to the shift register
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void setNumber(int* led, boolean* number)
|
||||
{
|
||||
for(int i = 0; i < 7; i++)
|
||||
{
|
||||
digitalWrite(led[i], number[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* A version of setColor that allows for using const boolean colors
|
||||
*/
|
||||
|
||||
void setNumber(int* led, const boolean* number)
|
||||
{
|
||||
boolean tempNumber[] = {number[0], number[1], number[2], number[3], number[4], number[5], number[6]};
|
||||
setNumber(led, tempNumber);
|
||||
}
|
||||
324
Projects/7 Segment Main/_2x7_Segment_74HC_Self/_2x7_Segment_74HC_Self.ino
Executable file
324
Projects/7 Segment Main/_2x7_Segment_74HC_Self/_2x7_Segment_74HC_Self.ino
Executable file
@@ -0,0 +1,324 @@
|
||||
/* ---------------------------------------------------------
|
||||
* | Arduino Experimentation Kit Example Code |
|
||||
* | CIRC-05 .: 8 More LEDs :. (74HC595 Shift Register) |
|
||||
* ---------------------------------------------------------
|
||||
*
|
||||
* We have already controlled 8 LEDs however this does it in a slightly
|
||||
* different manner. Rather than using 8 pins we will use just three
|
||||
* and an additional chip.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
//Pin Definitions
|
||||
//Pin Definitions
|
||||
//The 74HC595 uses a serial communication
|
||||
//link which has three pins
|
||||
int data = 2;
|
||||
int clock = 3;
|
||||
int latch = 4;
|
||||
|
||||
//Used for single LED manipulation
|
||||
int ledState = 0;
|
||||
const int ON = HIGH;
|
||||
const int OFF = LOW;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int ledDigitalOne[] = {13, 12, 11, 10, 9, 8, 7}; //the three digital pins of the digital LED
|
||||
//9 = redPin, 10 = greenPin, 11 = bluePin
|
||||
|
||||
const boolean ON1 = HIGH; //Define on as LOW (this is because we use a common
|
||||
//Anode RGB LED (common pin is connected to +5 volts)
|
||||
const boolean OFF1 = LOW; //Define off as HIGH
|
||||
|
||||
//Predefined Colors
|
||||
|
||||
const boolean One[] = {ON1, OFF1, OFF1, OFF1, OFF1, OFF1, ON1};
|
||||
const boolean Two[] = {OFF1, ON1, ON1, ON1, OFF1, ON1, ON1};
|
||||
const boolean Three[] = {ON1, ON1, OFF1, ON1, OFF1, ON1, ON1};
|
||||
const boolean Four[] = {ON1, OFF1, OFF1, ON1, ON1, OFF1, ON1};
|
||||
const boolean Five[] = {ON1, ON1, OFF1, ON1, ON1, ON1, OFF1};
|
||||
const boolean Six[] = {ON1, ON1, ON1, ON1, ON1, ON1, OFF1};
|
||||
const boolean Seven[] = {ON1, OFF1, OFF1, OFF1, OFF1, ON1, ON1};
|
||||
const boolean Eight[] = {ON1, ON1, ON1, ON1, ON1, ON1, ON1};
|
||||
const boolean Nine[] = {ON1, ON1, OFF1, ON1, ON1, ON1, ON1};
|
||||
const boolean Zero[] = {ON1, ON1, ON1, OFF1, ON1, ON1, ON1};
|
||||
|
||||
|
||||
//An Array that stores the predefined colors (allows us to later randomly display a color)
|
||||
const boolean* NUMBERS[] = {One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Zero};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(data, OUTPUT);
|
||||
pinMode(clock, OUTPUT);
|
||||
pinMode(latch, OUTPUT);
|
||||
|
||||
|
||||
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
pinMode(ledDigitalOne[i], OUTPUT); //Set the three LED pins as outputs
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* loop() - this function will start after setup finishes and then repeat
|
||||
* we set which LEDs we want on then call a routine which sends the states to the 74HC595
|
||||
*/
|
||||
void loop() // run over and over again
|
||||
{
|
||||
int delayTime = 500;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
changeLED(0,ON); // - 9
|
||||
changeLED(1,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, Nine);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 8
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, Eight);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 7
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, Seven);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 6
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
|
||||
setNumber(ledDigitalOne, Six);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 5
|
||||
changeLED(1,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
|
||||
setNumber(ledDigitalOne, Five);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 4
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, Four);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 3
|
||||
changeLED(1,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, Three);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - 2
|
||||
changeLED(2,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, Two);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 1
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, One);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 0
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, Zero);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* updateLEDs() - sends the LED states set in ledStates to the 74HC595
|
||||
* sequence
|
||||
*/
|
||||
void updateLEDs(int value){
|
||||
digitalWrite(latch, LOW); //Pulls the chips latch low
|
||||
shiftOut(data, clock, MSBFIRST, value); //Shifts out the 8 bits to the shift register
|
||||
digitalWrite(latch, HIGH); //Pulls the latch high displaying the data
|
||||
}
|
||||
|
||||
/*
|
||||
* updateLEDsLong() - sends the LED states set in ledStates to the 74HC595
|
||||
* sequence. Same as updateLEDs except the shifting out is done in software
|
||||
* so you can see what is happening.
|
||||
*/
|
||||
void updateLEDsLong(int value){
|
||||
digitalWrite(latch, LOW); //Pulls the chips latch low
|
||||
for(int i = 0; i < 8; i++){ //Will repeat 8 times (once for each bit)
|
||||
int bit = value & B10000000; //We use a "bitmask" to select only the eighth
|
||||
//bit in our number (the one we are addressing this time through
|
||||
value = value << 1; //we move our number up one bit value so next time bit 7 will be
|
||||
//bit 8 and we will do our math on it
|
||||
if(bit == 128){digitalWrite(data, HIGH);} //if bit 8 is set then set our data pin high
|
||||
else{digitalWrite(data, LOW);} //if bit 8 is unset then set the data pin low
|
||||
digitalWrite(clock, HIGH); //the next three lines pulse the clock pin
|
||||
delay(1);
|
||||
digitalWrite(clock, LOW);
|
||||
}
|
||||
digitalWrite(latch, HIGH); //pulls the latch high shifting our data into being displayed
|
||||
}
|
||||
|
||||
|
||||
//These are used in the bitwise math that we use to change individual LEDs
|
||||
//For more details http://en.wikipedia.org/wiki/Bitwise_operation
|
||||
int bits[] = {B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000};
|
||||
int masks[] = {B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111};
|
||||
/*
|
||||
* changeLED(int led, int state) - changes an individual LED
|
||||
* LEDs are 0 to 7 and state is either 0 - OFF or 1 - ON
|
||||
*/
|
||||
void changeLED(int led, int state){
|
||||
ledState = ledState & masks[led]; //clears ledState of the bit we are addressing
|
||||
if(state == ON){ledState = ledState | bits[led];} //if the bit is on we will add it to ledState
|
||||
updateLEDs(ledState); //send the new LED state to the shift register
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void setNumber(int* led, boolean* number)
|
||||
{
|
||||
for(int i = 0; i < 7; i++)
|
||||
{
|
||||
digitalWrite(led[i], number[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* A version of setColor that allows for using const boolean colors
|
||||
*/
|
||||
|
||||
void setNumber(int* led, const boolean* number)
|
||||
{
|
||||
boolean tempNumber[] = {number[0], number[1], number[2], number[3], number[4], number[5], number[6]};
|
||||
setNumber(led, tempNumber);
|
||||
}
|
||||
603
Projects/7 Segment Main/_2x7_Segment_74HC_Write/_2x7_Segment_74HC_Write.ino
Executable file
603
Projects/7 Segment Main/_2x7_Segment_74HC_Write/_2x7_Segment_74HC_Write.ino
Executable file
@@ -0,0 +1,603 @@
|
||||
/* ---------------------------------------------------------
|
||||
* | Arduino Experimentation Kit Example Code |
|
||||
* | CIRC-05 .: 8 More LEDs :. (74HC595 Shift Register) |
|
||||
* ---------------------------------------------------------
|
||||
*
|
||||
* We have already controlled 8 LEDs however this does it in a slightly
|
||||
* different manner. Rather than using 8 pins we will use just three
|
||||
* and an additional chip.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
//Pin Definitions
|
||||
//Pin Definitions
|
||||
//The 74HC595 uses a serial communication
|
||||
//link which has three pins
|
||||
int data = 2;
|
||||
int clock = 3;
|
||||
int latch = 4;
|
||||
|
||||
//Used for single LED manipulation
|
||||
int ledState = 0;
|
||||
const int ON = HIGH;
|
||||
const int OFF = LOW;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int ledDigitalOne[] = {13, 12, 11, 10, 9, 8, 7, 6}; //the three digital pins of the digital LED
|
||||
//9 = redPin, 10 = greenPin, 11 = bluePin
|
||||
|
||||
const boolean ON1 = HIGH; //Define on as LOW (this is because we use a common
|
||||
//Anode RGB LED (common pin is connected to +5 volts)
|
||||
const boolean OFF1 = LOW; //Define off as HIGH
|
||||
|
||||
//Predefined Colors
|
||||
|
||||
const boolean One[] = {ON1, OFF1, OFF1, OFF1, OFF1, OFF1, ON1};
|
||||
const boolean Two[] = {OFF1, ON1, ON1, ON1, OFF1, ON1, ON1};
|
||||
const boolean Three[] = {ON1, ON1, OFF1, ON1, OFF1, ON1, ON1};
|
||||
const boolean Four[] = {ON1, OFF1, OFF1, ON1, ON1, OFF1, ON1};
|
||||
const boolean Five[] = {ON1, ON1, OFF1, ON1, ON1, ON1, OFF1};
|
||||
const boolean Six[] = {ON1, ON1, ON1, ON1, ON1, ON1, OFF1};
|
||||
const boolean Seven[] = {ON1, OFF1, OFF1, OFF1, OFF1, ON1, ON1};
|
||||
const boolean Eight[] = {ON1, ON1, ON1, ON1, ON1, ON1, ON1};
|
||||
const boolean Nine[] = {ON1, ON1, OFF1, ON1, ON1, ON1, ON1};
|
||||
const boolean Zero[] = {ON1, ON1, ON1, OFF1, ON1, ON1, ON1};
|
||||
|
||||
const boolean A[] = {OFF1, ON1, OFF1, OFF1, OFF1, ON1, OFF1};
|
||||
const boolean B[] = {ON1, ON1, ON1, OFF1, ON1, ON1, ON1};
|
||||
const boolean C[] = {ON1, ON1, OFF1, OFF1, OFF1, OFF1, ON1};
|
||||
const boolean D[] = {ON1, ON1, OFF1, ON1, OFF1, OFF1, OFF1};
|
||||
const boolean E[] = {ON1, ON1, ON1, OFF1, OFF1, OFF1, ON1};
|
||||
const boolean F[] = {OFF1, ON1, OFF1, OFF1, OFF1, OFF1, OFF1};
|
||||
const boolean G[] = {ON1, ON1, OFF1, OFF1, ON1, ON1, ON1};
|
||||
const boolean H[] = {OFF1, ON1, ON1, OFF1, ON1, ON1, OFF1};
|
||||
const boolean I[] = {OFF1, OFF1, OFF1, ON1, OFF1, OFF1, OFF1};
|
||||
const boolean J[] = {ON1, ON1, OFF1, OFF1, OFF1, ON1, ON1};
|
||||
const boolean K[] = {OFF1, ON1, ON1, ON1, OFF1, OFF1, ON1};
|
||||
const boolean L[] = {ON1, ON1, OFF1, OFF1, OFF1, OFF1, ON1};
|
||||
const boolean M[] = {OFF1, ON1, OFF1, OFF1, OFF1, ON1, OFF1};
|
||||
const boolean N[] = {OFF1, ON1, OFF1, ON1, OFF1, ON1, ON1};
|
||||
const boolean O[] = {ON1, ON1, OFF1, OFF1, OFF1, ON1, ON1};
|
||||
const boolean P[] = {OFF1, ON1, OFF1, OFF1, OFF1, OFF1, OFF1};
|
||||
const boolean Q[] = {ON1, ON1, OFF1, OFF1, OFF1, ON1, OFF1};
|
||||
const boolean R[] = {OFF1, ON1, OFF1, ON1, OFF1, OFF1, ON1};
|
||||
const boolean S[] = {ON1, OFF1, OFF1, OFF1, OFF1, ON1, ON1};
|
||||
const boolean T[] = {OFF1, OFF1, OFF1, ON1, OFF1, OFF1, OFF1};
|
||||
const boolean U[] = {ON1, ON1, OFF1, OFF1, OFF1, ON1, ON1};
|
||||
const boolean V[] = {OFF1, OFF1, OFF1, ON1, OFF1, OFF1, OFF1};
|
||||
const boolean W[] = {ON1, ON1, OFF1, ON1, OFF1, ON1, ON1};
|
||||
const boolean X[] = {OFF1, ON1, OFF1, OFF1, OFF1, ON1, OFF1};
|
||||
const boolean Y[] = {OFF1, OFF1, OFF1, ON1, OFF1, OFF1, OFF1};
|
||||
const boolean Z[] = {ON1, ON1, ON1, OFF1, OFF1, OFF1, ON1};
|
||||
const boolean EXCLA[] = {OFF1, ON1, OFF1, OFF1, OFF1, OFF1, OFF1, ON1};
|
||||
|
||||
|
||||
//An Array that stores the predefined colors (allows us to later randomly display a color)
|
||||
const boolean* NUMBERS[] = {One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Zero};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(data, OUTPUT);
|
||||
pinMode(clock, OUTPUT);
|
||||
pinMode(latch, OUTPUT);
|
||||
|
||||
|
||||
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
pinMode(ledDigitalOne[i], OUTPUT); //Set the three LED pins as outputs
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* loop() - this function will start after setup finishes and then repeat
|
||||
* we set which LEDs we want on then call a routine which sends the states to the 74HC595
|
||||
*/
|
||||
void loop() // run over and over again
|
||||
{
|
||||
int delayTime = 500;
|
||||
for (int i = 0; i < 31; i++)
|
||||
{
|
||||
changeLED(0,ON); // - A
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, A);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - B
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, B);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - C
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
|
||||
setNumber(ledDigitalOne, C);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - D
|
||||
changeLED(2,ON);
|
||||
changeLED(3,ON);
|
||||
|
||||
setNumber(ledDigitalOne, D);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // -- E
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
|
||||
setNumber(ledDigitalOne, E);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // -- F
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
|
||||
setNumber(ledDigitalOne, F);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // -- G
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
|
||||
setNumber(ledDigitalOne, G);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // -- H
|
||||
changeLED(1,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, H);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(3,ON); // - I
|
||||
|
||||
setNumber(ledDigitalOne, I);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(5,ON); // - j
|
||||
|
||||
setNumber(ledDigitalOne, J);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // -- K
|
||||
changeLED(1,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
|
||||
setNumber(ledDigitalOne, K);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - L
|
||||
|
||||
setNumber(ledDigitalOne, L);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - M
|
||||
changeLED(2,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
|
||||
setNumber(ledDigitalOne, M);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - N
|
||||
changeLED(2,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(5,ON);
|
||||
|
||||
setNumber(ledDigitalOne, N);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - 0
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
|
||||
setNumber(ledDigitalOne, O);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // -- P
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, P);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - Q
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
|
||||
setNumber(ledDigitalOne, Q);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // -- R
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, R);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // -- S
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, S);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(2,ON); // - T
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
|
||||
setNumber(ledDigitalOne, T);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - U
|
||||
changeLED(5,ON);
|
||||
|
||||
setNumber(ledDigitalOne, U);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - V
|
||||
changeLED(5,ON);
|
||||
|
||||
setNumber(ledDigitalOne, V);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - W
|
||||
changeLED(5,ON);
|
||||
|
||||
setNumber(ledDigitalOne, W);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - X
|
||||
changeLED(5,ON);
|
||||
|
||||
setNumber(ledDigitalOne, X);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // -- Y
|
||||
changeLED(1,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, Y);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(2,ON); // - Z
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
|
||||
setNumber(ledDigitalOne, Z);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - EXCLA
|
||||
changeLED(7,ON);
|
||||
|
||||
setNumber(ledDigitalOne, EXCLA);
|
||||
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
changeLED(7,OFF);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* updateLEDs() - sends the LED states set in ledStates to the 74HC595
|
||||
* sequence
|
||||
*/
|
||||
void updateLEDs(int value){
|
||||
digitalWrite(latch, LOW); //Pulls the chips latch low
|
||||
shiftOut(data, clock, MSBFIRST, value); //Shifts out the 8 bits to the shift register
|
||||
digitalWrite(latch, HIGH); //Pulls the latch high displaying the data
|
||||
}
|
||||
|
||||
/*
|
||||
* updateLEDsLong() - sends the LED states set in ledStates to the 74HC595
|
||||
* sequence. Same as updateLEDs except the shifting out is done in software
|
||||
* so you can see what is happening.
|
||||
*/
|
||||
void updateLEDsLong(int value){
|
||||
digitalWrite(latch, LOW); //Pulls the chips latch low
|
||||
for(int i = 0; i < 8; i++){ //Will repeat 8 times (once for each bit)
|
||||
int bit = value & B10000000; //We use a "bitmask" to select only the eighth
|
||||
//bit in our number (the one we are addressing this time through
|
||||
value = value << 1; //we move our number up one bit value so next time bit 7 will be
|
||||
//bit 8 and we will do our math on it
|
||||
if(bit == 128){digitalWrite(data, HIGH);} //if bit 8 is set then set our data pin high
|
||||
else{digitalWrite(data, LOW);} //if bit 8 is unset then set the data pin low
|
||||
digitalWrite(clock, HIGH); //the next three lines pulse the clock pin
|
||||
delay(1);
|
||||
digitalWrite(clock, LOW);
|
||||
}
|
||||
digitalWrite(latch, HIGH); //pulls the latch high shifting our data into being displayed
|
||||
}
|
||||
|
||||
|
||||
//These are used in the bitwise math that we use to change individual LEDs
|
||||
//For more details http://en.wikipedia.org/wiki/Bitwise_operation
|
||||
int bits[] = {B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000};
|
||||
int masks[] = {B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111};
|
||||
/*
|
||||
* changeLED(int led, int state) - changes an individual LED
|
||||
* LEDs are 0 to 7 and state is either 0 - OFF or 1 - ON
|
||||
*/
|
||||
void changeLED(int led, int state){
|
||||
ledState = ledState & masks[led]; //clears ledState of the bit we are addressing
|
||||
if(state == ON){ledState = ledState | bits[led];} //if the bit is on we will add it to ledState
|
||||
updateLEDs(ledState); //send the new LED state to the shift register
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void setNumber(int* led, boolean* number)
|
||||
{
|
||||
for(int i = 0; i < 7; i++)
|
||||
{
|
||||
digitalWrite(led[i], number[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* A version of setColor that allows for using const boolean colors
|
||||
*/
|
||||
|
||||
void setNumber(int* led, const boolean* number)
|
||||
{
|
||||
boolean tempNumber[] = {number[0], number[1], number[2], number[3], number[4], number[5], number[6]};
|
||||
setNumber(led, tempNumber);
|
||||
}
|
||||
288
Projects/7 Segment Main/_7_Segment/_7_Segment.ino
Executable file
288
Projects/7 Segment Main/_7_Segment/_7_Segment.ino
Executable file
@@ -0,0 +1,288 @@
|
||||
/*
|
||||
Make Projects: How to Drive a 7 Segment LED
|
||||
URL:
|
||||
By: Riley Porter
|
||||
This is an introduction on how to drive a 7 Segment LED using only a Arduino. This is
|
||||
not the best way to do this. This is meant to be a learning excercise. In later tutorials
|
||||
I will show you how to use an dedicated IC using SPI or a Shift Register. Enjoy.
|
||||
*/
|
||||
|
||||
digitalWrite(A, HIGH) = turn off the "A" segment in the LED display
|
||||
digitalWrite(B, LOW) = turn on the "B" segment in the LED display
|
||||
|
||||
|
||||
|
||||
#define A 8
|
||||
#define B 9
|
||||
#define C 2
|
||||
#define D 3
|
||||
#define E 4
|
||||
#define F 5
|
||||
#define G 6
|
||||
|
||||
|
||||
|
||||
|
||||
void clr()
|
||||
{
|
||||
//Clears the LED
|
||||
digitalWrite(A, HIGH);
|
||||
digitalWrite(B, HIGH);
|
||||
digitalWrite(C, HIGH);
|
||||
digitalWrite(D, HIGH);
|
||||
digitalWrite(E, HIGH);
|
||||
digitalWrite(F, HIGH);
|
||||
digitalWrite(G, HIGH);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void char_A()
|
||||
{
|
||||
digitalWrite(D, HIGH);
|
||||
digitalWrite(E, LOW);
|
||||
digitalWrite(F, LOW);
|
||||
digitalWrite(G, LOW);
|
||||
digitalWrite(A, LOW);
|
||||
digitalWrite(B, LOW);
|
||||
digitalWrite(C, LOg9tW);
|
||||
}
|
||||
z
|
||||
void char_B()
|
||||
{
|
||||
//Displays B
|
||||
digitalWrite(D, LOW);
|
||||
digitalWrite(E, LOW);
|
||||
digitalWrite(F, LOW);
|
||||
digitalWrite(G, LOW);
|
||||
digitalWrite(A, HIGH);
|
||||
digitalWrite(B, HIGH);
|
||||
digitalWrite(C, LOW);
|
||||
}
|
||||
|
||||
void char_C()
|
||||
{
|
||||
//Displays C
|
||||
digitalWrite(D, LOW);
|
||||
digitalWrite(E, LOW);
|
||||
digitalWrite(F, LOW);
|
||||
digitalWrite(G, HIGH);
|
||||
digitalWrite(A, LOW);
|
||||
digitalWrite(B, HIGH);
|
||||
digitalWrite(C, HIGH);
|
||||
}
|
||||
|
||||
void char_D()
|
||||
{
|
||||
//Displays D
|
||||
digitalWrite(D, LOW);
|
||||
digitalWrite(E, LOW);
|
||||
digitalWrite(F, HIGH);
|
||||
digitalWrite(G, LOW);
|
||||
digitalWrite(A, HIGH);
|
||||
digitalWrite(B, LOW);
|
||||
digitalWrite(C, LOW);
|
||||
}
|
||||
|
||||
void char_E()
|
||||
{
|
||||
//Displays E
|
||||
digitalWrite(D, LOW);
|
||||
digitalWrite(E, LOW);
|
||||
digitalWrite(F, LOW);
|
||||
digitalWrite(G, LOW);
|
||||
digitalWrite(A, LOW);
|
||||
digitalWrite(B, HIGH);
|
||||
digitalWrite(C, HIGH);
|
||||
}
|
||||
|
||||
void char_F()
|
||||
{
|
||||
//Displays F
|
||||
digitalWrite(D, HIGH);
|
||||
digitalWrite(E, LOW);
|
||||
digitalWrite(F, LOW);
|
||||
digitalWrite(G, LOW);
|
||||
digitalWrite(A, LOW);
|
||||
digitalWrite(B, HIGH);
|
||||
digitalWrite(C, HIGH);
|
||||
}
|
||||
|
||||
|
||||
void one()
|
||||
{
|
||||
//Displays 1
|
||||
digitalWrite(D, HIGH);
|
||||
digitalWrite(E, LOW);
|
||||
digitalWrite(F, LOW);
|
||||
digitalWrite(G, HIGH);
|
||||
digitalWrite(A, HIGH);
|
||||
digitalWrite(B, HIGH);
|
||||
digitalWrite(C, HIGH);
|
||||
}
|
||||
|
||||
void two()
|
||||
{
|
||||
//Displays 2
|
||||
digitalWrite(D, LOW);
|
||||
digitalWrite(E, LOW);
|
||||
digitalWrite(F, HIGH);
|
||||
digitalWrite(G, LOW);
|
||||
digitalWrite(A, LOW);
|
||||
digitalWrite(B, LOW);
|
||||
digitalWrite(C, HIGH);
|
||||
}
|
||||
|
||||
void three()
|
||||
{
|
||||
//Displays 3
|
||||
digitalWrite(D, LOW);
|
||||
digitalWrite(E, HIGH);
|
||||
digitalWrite(F, HIGH);
|
||||
digitalWrite(G, LOW);
|
||||
digitalWrite(A, LOW);
|
||||
digitalWrite(B, LOW);
|
||||
digitalWrite(C, LOW);
|
||||
}
|
||||
|
||||
void four()
|
||||
{
|
||||
//Displays 4
|
||||
digitalWrite(D, HIGH);
|
||||
digitalWrite(E, HIGH);
|
||||
digitalWrite(F, LOW);
|
||||
digitalWrite(G, LOW);
|
||||
digitalWrite(A, HIGH);
|
||||
digitalWrite(B, LOW);
|
||||
digitalWrite(C, LOW);
|
||||
}
|
||||
|
||||
void five()
|
||||
{
|
||||
//Displays 5
|
||||
digitalWrite(D, LOW);
|
||||
digitalWrite(E, HIGH);
|
||||
digitalWrite(F, LOW);
|
||||
digitalWrite(G, LOW);
|
||||
digitalWrite(A, LOW);
|
||||
digitalWrite(B, HIGH);
|
||||
digitalWrite(C, LOW);
|
||||
}
|
||||
|
||||
void six()
|
||||
{
|
||||
//Displays 6
|
||||
digitalWrite(D, LOW);
|
||||
digitalWrite(E, LOW);
|
||||
digitalWrite(F, LOW);
|
||||
digitalWrite(G, LOW);
|
||||
digitalWrite(A, LOW);
|
||||
digitalWrite(B, HIGH);
|
||||
digitalWrite(C, LOW);
|
||||
}
|
||||
|
||||
void seven()
|
||||
{
|
||||
//Displays 7
|
||||
digitalWrite(D, HIGH);
|
||||
digitalWrite(E, HIGH);
|
||||
digitalWrite(F, HIGH);
|
||||
digitalWrite(G, HIGH);
|
||||
digitalWrite(A, LOW);
|
||||
digitalWrite(B, LOW);
|
||||
digitalWrite(C, LOW);
|
||||
}
|
||||
|
||||
void eight()
|
||||
{
|
||||
//Displays 8
|
||||
digitalWrite(D, LOW);
|
||||
digitalWrite(E, LOW);
|
||||
digitalWrite(F, LOW);
|
||||
digitalWrite(G, LOW);
|
||||
digitalWrite(A, LOW);
|
||||
digitalWrite(B, LOW);
|
||||
digitalWrite(C, LOW);
|
||||
}
|
||||
|
||||
void nine()
|
||||
{
|
||||
//Displays 9
|
||||
digitalWrite(D, LOW);
|
||||
digitalWrite(E, HIGH);
|
||||
digitalWrite(F, LOW);
|
||||
digitalWrite(G, LOW);
|
||||
digitalWrite(A, LOW);
|
||||
digitalWrite(B, LOW);
|
||||
digitalWrite(C, LOW);
|
||||
}
|
||||
|
||||
void zero()
|
||||
{
|
||||
//Displays 0
|
||||
digitalWrite(D, LOW);
|
||||
digitalWrite(E, LOW);
|
||||
digitalWrite(F, LOW);
|
||||
digitalWrite(G, HIGH);
|
||||
digitalWrite(A, LOW);
|
||||
digitalWrite(B, LOW);
|
||||
digitalWrite(C, LOW);
|
||||
}
|
||||
|
||||
void LoopDisplay()
|
||||
{
|
||||
//Loop through all Chars and Numbers
|
||||
char_A();
|
||||
delay(1000);
|
||||
char_B();
|
||||
delay(1000);
|
||||
char_C();
|
||||
delay(1000);
|
||||
char_D();
|
||||
delay(1000);
|
||||
char_E();
|
||||
delay(1000);
|
||||
char_F();
|
||||
delay(1000);
|
||||
one();
|
||||
delay(1000);
|
||||
two();
|
||||
delay(1000);
|
||||
three();
|
||||
delay(1000);
|
||||
four();
|
||||
delay(1000);
|
||||
five();
|
||||
delay(1000);
|
||||
six();
|
||||
delay(1000);
|
||||
seven();
|
||||
delay(1000);
|
||||
eight();
|
||||
delay(1000);
|
||||
nine();
|
||||
delay(1000);
|
||||
zero();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
//Setup our pins
|
||||
pinMode(A, OUTPUT);
|
||||
pinMode(B, OUTPUT);
|
||||
pinMode(C, OUTPUT);
|
||||
pinMode(D, OUTPUT);
|
||||
pinMode(E, OUTPUT);
|
||||
pinMode(F, OUTPUT);
|
||||
pinMode(G, OUTPUT);
|
||||
Serial.begin(9600); //Begin serial communcation
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("Starting\n");
|
||||
LoopDisplay();
|
||||
|
||||
}
|
||||
98
Projects/7 Segment Main/_7_Segment_Letters/_7_Segment_Letters.ino
Executable file
98
Projects/7 Segment Main/_7_Segment_Letters/_7_Segment_Letters.ino
Executable file
@@ -0,0 +1,98 @@
|
||||
int ledDigitalOne[] = {1, 2, 3, 4, 5, 6, 7}; //the three digital pins of the digital LED
|
||||
//9 = redPin, 10 = greenPin, 11 = bluePin
|
||||
|
||||
const boolean ON = HIGH; //Define on as LOW (this is because we use a common
|
||||
//Anode RGB LED (common pin is connected to +5 volts)
|
||||
const boolean OFF = LOW; //Define off as HIGH
|
||||
|
||||
//Predefined Colors
|
||||
|
||||
const boolean One[] = {OFF, ON, OFF, OFF, OFF, OFF, ON};
|
||||
const boolean Two[] = {ON, OFF, ON, ON, OFF, ON, ON};
|
||||
const boolean Three[] = {ON, ON, OFF, ON, OFF, ON, ON};
|
||||
const boolean Four[] = {OFF, ON, OFF, ON, ON, OFF, ON};
|
||||
const boolean Five[] = {ON, ON, OFF, ON, ON, ON, OFF};
|
||||
const boolean Six[] = {ON, ON, ON, ON, ON, ON, OFF};
|
||||
const boolean Seven[] = {OFF, ON, OFF, OFF, OFF, ON, ON};
|
||||
const boolean Eight[] = {ON, ON, ON, ON, ON, ON, ON};
|
||||
const boolean Nine[] = {ON, ON, OFF, ON, ON, ON, ON};
|
||||
const boolean Zero[] = {ON, ON, ON, OFF, ON, ON, ON};
|
||||
|
||||
//An Array that stores the predefined colors (allows us to later randomly display a color)
|
||||
const boolean* NUMBERS[] = {One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Zero};
|
||||
|
||||
void setup(){
|
||||
for(int i = 0; i < 9; i++){
|
||||
pinMode(ledDigitalOne[i], OUTPUT); //Set the three LED pins as outputs
|
||||
}
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
/* Example - 1 Set a color
|
||||
Set the three LEDs to any predefined color
|
||||
*/
|
||||
|
||||
|
||||
setNumber(ledDigitalOne, Eight); //Set the color of LED one
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
setNumber(ledDigitalOne, Nine);
|
||||
delay (1000);
|
||||
setNumber(ledDigitalOne, Eight);
|
||||
delay (1000);
|
||||
setNumber(ledDigitalOne, Seven);
|
||||
delay (1000);
|
||||
setNumber(ledDigitalOne, Six);
|
||||
delay (1000);
|
||||
setNumber(ledDigitalOne, Five);
|
||||
delay (1000);
|
||||
setNumber(ledDigitalOne, Four);
|
||||
delay (1000);
|
||||
setNumber(ledDigitalOne, Three);
|
||||
delay (1000);
|
||||
setNumber(ledDigitalOne, Two);
|
||||
delay (1000);
|
||||
setNumber(ledDigitalOne, One);
|
||||
delay (1000);
|
||||
setNumber(ledDigitalOne, Zero);
|
||||
delay (1000);
|
||||
}
|
||||
|
||||
/* Example - 2 Go through Random Colors
|
||||
Set the LEDs to a random color
|
||||
*/
|
||||
//randomNumber();
|
||||
|
||||
}
|
||||
|
||||
//void randomNumber(){
|
||||
//int rand = random(0, sizeof(NUMBER / 2); //get a random number within the range of colors
|
||||
//setNumber(ledDigitalOne, NUMBER[rand]); //Set the color of led one to a random color
|
||||
//delay(1000);
|
||||
//}
|
||||
|
||||
/* Sets an led to any color
|
||||
led - a three element array defining the three color pins (led[0] = redPin, led[1] = greenPin, led[2] = bluePin)
|
||||
color - a three element boolean array (color[0] = red value (LOW = on, HIGH = off), color[1] = green value, color[2] =blue value)
|
||||
*/
|
||||
|
||||
void setNumber(int* led, boolean* number)
|
||||
{
|
||||
for(int i = 0; i < 7; i++)
|
||||
{
|
||||
digitalWrite(led[i], number[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* A version of setColor that allows for using const boolean colors
|
||||
*/
|
||||
|
||||
void setNumber(int* led, const boolean* number)
|
||||
{
|
||||
boolean tempNumber[] = {number[0], number[1], number[2], number[3], number[4], number[5], number[6]};
|
||||
setNumber(led, tempNumber);
|
||||
}
|
||||
// the loop routine runs over and over again forever:
|
||||
|
||||
98
Projects/7 Segment Main/_7_Segment_Self/_7_Segment_Self.ino
Executable file
98
Projects/7 Segment Main/_7_Segment_Self/_7_Segment_Self.ino
Executable file
@@ -0,0 +1,98 @@
|
||||
int ledDigitalOne[] = {13, 12, 11, 10, 9, 8, 7}; //the three digital pins of the digital LED
|
||||
//9 = redPin, 10 = greenPin, 11 = bluePin
|
||||
|
||||
const boolean ON = HIGH; //Define on as LOW (this is because we use a common
|
||||
//Anode RGB LED (common pin is connected to +5 volts)
|
||||
const boolean OFF = LOW; //Define off as HIGH
|
||||
|
||||
//Predefined Colors
|
||||
|
||||
const boolean One[] = {ON, OFF, OFF, OFF, OFF, OFF, ON};
|
||||
const boolean Two[] = {OFF, ON, ON, ON, OFF, ON, ON};
|
||||
const boolean Three[] = {ON, ON, OFF, ON, OFF, ON, ON};
|
||||
const boolean Four[] = {ON, OFF, OFF, ON, ON, OFF, ON};
|
||||
const boolean Five[] = {ON, ON, OFF, ON, ON, ON, OFF};
|
||||
const boolean Six[] = {ON, ON, ON, ON, ON, ON, OFF};
|
||||
const boolean Seven[] = {ON, OFF, OFF, OFF, OFF, ON, ON};
|
||||
const boolean Eight[] = {ON, ON, ON, ON, ON, ON, ON};
|
||||
const boolean Nine[] = {ON, ON, OFF, ON, ON, ON, ON};
|
||||
const boolean Zero[] = {ON, ON, ON, OFF, ON, ON, ON};
|
||||
|
||||
//An Array that stores the predefined colors (allows us to later randomly display a color)
|
||||
const boolean* NUMBERS[] = {One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Zero};
|
||||
|
||||
void setup(){
|
||||
for(int i = 0; i < 9; i++){
|
||||
pinMode(ledDigitalOne[i], OUTPUT); //Set the three LED pins as outputs
|
||||
}
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
/* Example - 1 Set a color
|
||||
Set the three LEDs to any predefined color
|
||||
*/
|
||||
|
||||
|
||||
setNumber(ledDigitalOne, Eight); //Set the color of LED one
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
setNumber(ledDigitalOne, Nine);
|
||||
delay (500);
|
||||
setNumber(ledDigitalOne, Eight);
|
||||
delay (500);
|
||||
setNumber(ledDigitalOne, Seven);
|
||||
delay (500);
|
||||
setNumber(ledDigitalOne, Six);
|
||||
delay (500);
|
||||
setNumber(ledDigitalOne, Five);
|
||||
delay (500);
|
||||
setNumber(ledDigitalOne, Four);
|
||||
delay (500);
|
||||
setNumber(ledDigitalOne, Three);
|
||||
delay (500);
|
||||
setNumber(ledDigitalOne, Two);
|
||||
delay (500);
|
||||
setNumber(ledDigitalOne, One);
|
||||
delay (500);
|
||||
setNumber(ledDigitalOne, Zero);
|
||||
delay (500);
|
||||
}
|
||||
|
||||
/* Example - 2 Go through Random Colors
|
||||
Set the LEDs to a random color
|
||||
*/
|
||||
//randomNumber();
|
||||
|
||||
}
|
||||
|
||||
//void randomNumber(){
|
||||
//int rand = random(0, sizeof(NUMBER / 2); //get a random number within the range of colors
|
||||
//setNumber(ledDigitalOne, NUMBER[rand]); //Set the color of led one to a random color
|
||||
//delay(1000);
|
||||
//}
|
||||
|
||||
/* Sets an led to any color
|
||||
led - a three element array defining the three color pins (led[0] = redPin, led[1] = greenPin, led[2] = bluePin)
|
||||
color - a three element boolean array (color[0] = red value (LOW = on, HIGH = off), color[1] = green value, color[2] =blue value)
|
||||
*/
|
||||
|
||||
void setNumber(int* led, boolean* number)
|
||||
{
|
||||
for(int i = 0; i < 7; i++)
|
||||
{
|
||||
digitalWrite(led[i], number[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* A version of setColor that allows for using const boolean colors
|
||||
*/
|
||||
|
||||
void setNumber(int* led, const boolean* number)
|
||||
{
|
||||
boolean tempNumber[] = {number[0], number[1], number[2], number[3], number[4], number[5], number[6]};
|
||||
setNumber(led, tempNumber);
|
||||
}
|
||||
// the loop routine runs over and over again forever:
|
||||
|
||||
98
Projects/7 Segment Main/_7_Segment_w__74HC/_7_Segment_w__74HC.ino
Executable file
98
Projects/7 Segment Main/_7_Segment_w__74HC/_7_Segment_w__74HC.ino
Executable file
@@ -0,0 +1,98 @@
|
||||
/* ---------------------------------------------------------
|
||||
* | Arduino Experimentation Kit Example Code |
|
||||
* | CIRC-05 .: 8 More LEDs :. (74HC595 Shift Register) |
|
||||
* ---------------------------------------------------------
|
||||
*
|
||||
* We have already controlled 8 LEDs however this does it in a slightly
|
||||
* different manner. Rather than using 8 pins we will use just three
|
||||
* and an additional chip.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
//Pin Definitions
|
||||
//Pin Definitions
|
||||
//The 74HC595 uses a serial communication
|
||||
//link which has three pins
|
||||
int data = 11;
|
||||
int latch = 12;
|
||||
int clock = 13;
|
||||
|
||||
//Used for single LED manipulation
|
||||
int ledState = 1;
|
||||
const int ON = HIGH;
|
||||
const int OFF = LOW;
|
||||
|
||||
|
||||
/*
|
||||
* setup() - this function runs once when you turn your Arduino on
|
||||
* We set the three control pins to outputs
|
||||
*/
|
||||
void setup()
|
||||
{
|
||||
pinMode(data, OUTPUT);
|
||||
pinMode(clock, OUTPUT);
|
||||
pinMode(latch, OUTPUT);
|
||||
}
|
||||
|
||||
/*
|
||||
* loop() - this function will start after setup finishes and then repeat
|
||||
* we set which LEDs we want on then call a routine which sends the states to the 74HC595
|
||||
*/
|
||||
void loop() // run over and over again
|
||||
{
|
||||
int delayTime = 100; //the number of milliseconds to delay between LED updates
|
||||
for(int i = 0; i < 256; i++){
|
||||
updateLEDs(i);
|
||||
delay(delayTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* updateLEDs() - sends the LED states set in ledStates to the 74HC595
|
||||
* sequence
|
||||
*/
|
||||
void updateLEDs(int value){
|
||||
digitalWrite(latch, LOW); //Pulls the chips latch low
|
||||
shiftOut(data, clock, MSBFIRST, value); //Shifts out the 8 bits to the shift register
|
||||
digitalWrite(latch, HIGH); //Pulls the latch high displaying the data
|
||||
}
|
||||
|
||||
/*
|
||||
* updateLEDsLong() - sends the LED states set in ledStates to the 74HC595
|
||||
* sequence. Same as updateLEDs except the shifting out is done in software
|
||||
* so you can see what is happening.
|
||||
*/
|
||||
void updateLEDsLong(int value){
|
||||
digitalWrite(latch, LOW); //Pulls the chips latch low
|
||||
for(int i = 0; i < 8; i++){ //Will repeat 8 times (once for each bit)
|
||||
int bit = value & B10000000; //We use a "bitmask" to select only the eighth
|
||||
//bit in our number (the one we are addressing this time through
|
||||
value = value << 1; //we move our number up one bit value so next time bit 7 will be
|
||||
//bit 8 and we will do our math on it
|
||||
if(bit == 128){digitalWrite(data, HIGH);} //if bit 8 is set then set our data pin high
|
||||
else{digitalWrite(data, LOW);} //if bit 8 is unset then set the data pin low
|
||||
digitalWrite(clock, HIGH); //the next three lines pulse the clock pin
|
||||
delay(1);
|
||||
digitalWrite(clock, LOW);
|
||||
}
|
||||
digitalWrite(latch, HIGH); //pulls the latch high shifting our data into being displayed
|
||||
}
|
||||
|
||||
|
||||
//These are used in the bitwise math that we use to change individual LEDs
|
||||
//For more details http://en.wikipedia.org/wiki/Bitwise_operation
|
||||
int bits[] = {B0000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000};
|
||||
int masks[] = {B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111};
|
||||
/*
|
||||
* changeLED(int led, int state) - changes an individual LED
|
||||
* LEDs are 0 to 7 and state is either 0 - OFF or 1 - ON
|
||||
*/
|
||||
void changeLED(int led, int state){
|
||||
ledState = ledState & masks[led]; //clears ledState of the bit we are addressing
|
||||
if(state == ON){ledState = ledState | bits[led];} //if the bit is on we will add it to ledState
|
||||
updateLEDs(ledState); //send the new LED state to the shift register
|
||||
}
|
||||
236
Projects/7 Segment Main/_8_LED_74HC/_8_LED_74HC.ino
Executable file
236
Projects/7 Segment Main/_8_LED_74HC/_8_LED_74HC.ino
Executable file
@@ -0,0 +1,236 @@
|
||||
/* ---------------------------------------------------------
|
||||
* | Arduino Experimentation Kit Example Code |
|
||||
* | CIRC-05 .: 8 More LEDs :. (74HC595 Shift Register) |
|
||||
* ---------------------------------------------------------
|
||||
*
|
||||
* We have already controlled 8 LEDs however this does it in a slightly
|
||||
* different manner. Rather than using 8 pins we will use just three
|
||||
* and an additional chip.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
//Pin Definitions
|
||||
//Pin Definitions
|
||||
//The 74HC595 uses a serial communication
|
||||
//link which has three pins
|
||||
int data = 2;
|
||||
int clock = 3;
|
||||
int latch = 4;
|
||||
|
||||
//Used for single LED manipulation
|
||||
int ledState = 0;
|
||||
const int ON = HIGH;
|
||||
const int OFF = LOW;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(data, OUTPUT);
|
||||
pinMode(clock, OUTPUT);
|
||||
pinMode(latch, OUTPUT);
|
||||
}
|
||||
|
||||
/*
|
||||
* loop() - this function will start after setup finishes and then repeat
|
||||
* we set which LEDs we want on then call a routine which sends the states to the 74HC595
|
||||
*/
|
||||
void loop() // run over and over again
|
||||
{
|
||||
int delayTime = 500;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
changeLED(0,ON); // - 9
|
||||
changeLED(1,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 8
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 7
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 6
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 5
|
||||
changeLED(1,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 4
|
||||
changeLED(3,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(6,ON);
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 3
|
||||
changeLED(1,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(1,ON); // - 2
|
||||
changeLED(2,ON);
|
||||
changeLED(3,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 1
|
||||
changeLED(6,ON);
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
|
||||
changeLED(0,ON); // - 0
|
||||
changeLED(1,ON);
|
||||
changeLED(2,ON);
|
||||
changeLED(4,ON);
|
||||
changeLED(5,ON);
|
||||
changeLED(6,ON);
|
||||
delay(1000);
|
||||
changeLED(0,OFF);
|
||||
changeLED(1,OFF);
|
||||
changeLED(2,OFF);
|
||||
changeLED(3,OFF);
|
||||
changeLED(4,OFF);
|
||||
changeLED(5,OFF);
|
||||
changeLED(6,OFF);
|
||||
}
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
changeLED(i,OFF);
|
||||
delay(delayTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* updateLEDs() - sends the LED states set in ledStates to the 74HC595
|
||||
* sequence
|
||||
*/
|
||||
void updateLEDs(int value){
|
||||
digitalWrite(latch, LOW); //Pulls the chips latch low
|
||||
shiftOut(data, clock, MSBFIRST, value); //Shifts out the 8 bits to the shift register
|
||||
digitalWrite(latch, HIGH); //Pulls the latch high displaying the data
|
||||
}
|
||||
|
||||
/*
|
||||
* updateLEDsLong() - sends the LED states set in ledStates to the 74HC595
|
||||
* sequence. Same as updateLEDs except the shifting out is done in software
|
||||
* so you can see what is happening.
|
||||
*/
|
||||
void updateLEDsLong(int value){
|
||||
digitalWrite(latch, LOW); //Pulls the chips latch low
|
||||
for(int i = 0; i < 8; i++){ //Will repeat 8 times (once for each bit)
|
||||
int bit = value & B10000000; //We use a "bitmask" to select only the eighth
|
||||
//bit in our number (the one we are addressing this time through
|
||||
value = value << 1; //we move our number up one bit value so next time bit 7 will be
|
||||
//bit 8 and we will do our math on it
|
||||
if(bit == 128){digitalWrite(data, HIGH);} //if bit 8 is set then set our data pin high
|
||||
else{digitalWrite(data, LOW);} //if bit 8 is unset then set the data pin low
|
||||
digitalWrite(clock, HIGH); //the next three lines pulse the clock pin
|
||||
delay(1);
|
||||
digitalWrite(clock, LOW);
|
||||
}
|
||||
digitalWrite(latch, HIGH); //pulls the latch high shifting our data into being displayed
|
||||
}
|
||||
|
||||
|
||||
//These are used in the bitwise math that we use to change individual LEDs
|
||||
//For more details http://en.wikipedia.org/wiki/Bitwise_operation
|
||||
int bits[] = {B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000};
|
||||
int masks[] = {B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111};
|
||||
/*
|
||||
* changeLED(int led, int state) - changes an individual LED
|
||||
* LEDs are 0 to 7 and state is either 0 - OFF or 1 - ON
|
||||
*/
|
||||
void changeLED(int led, int state){
|
||||
ledState = ledState & masks[led]; //clears ledState of the bit we are addressing
|
||||
if(state == ON){ledState = ledState | bits[led];} //if the bit is on we will add it to ledState
|
||||
updateLEDs(ledState); //send the new LED state to the shift register
|
||||
}
|
||||
109
Projects/7x5 Display/_1.singleTest/_1.singleTest.ino
Normal file
109
Projects/7x5 Display/_1.singleTest/_1.singleTest.ino
Normal file
@@ -0,0 +1,109 @@
|
||||
byte led_row[7] = {5,2,6,11,7,13,8};
|
||||
byte led_col[5] = {3,9,10,4,12};
|
||||
long prevTime = -1000;
|
||||
long interval = 5000;
|
||||
|
||||
byte draw_task[7][5] = {
|
||||
{ 0,1,1,0,0},
|
||||
{ 0,0,1,0,0},
|
||||
{ 0,0,1,0,0},
|
||||
{ 0,0,1,0,0},
|
||||
{ 0,0,1,0,0},
|
||||
{ 0,0,1,0,0},
|
||||
{ 0,0,1,0,0}};
|
||||
|
||||
byte zero[7][5] = {
|
||||
{ 0,1,1,1,0},
|
||||
{ 1,0,0,0,1},
|
||||
{ 1,0,0,0,1},
|
||||
{ 1,0,0,0,1},
|
||||
{ 1,0,0,0,1},
|
||||
{ 1,0,0,0,1},
|
||||
{ 0,1,1,1,0}};
|
||||
|
||||
byte one[7][5] = {
|
||||
{ 0,1,1,0,0},
|
||||
{ 1,0,1,0,0},
|
||||
{ 0,0,1,0,0},
|
||||
{ 0,0,1,0,0},
|
||||
{ 0,0,1,0,0},
|
||||
{ 0,0,1,0,0},
|
||||
{ 1,1,1,1,1}};
|
||||
|
||||
byte two[7][5] = {
|
||||
{ 1,0,0,0,1},
|
||||
{ 0,1,0,1,0},
|
||||
{ 0,1,0,1,0},
|
||||
{ 0,0,1,0,0},
|
||||
{ 0,1,0,1,0},
|
||||
{ 0,1,0,1,0},
|
||||
{ 1,0,0,0,1}};
|
||||
|
||||
byte three[7][5] = {
|
||||
{ 1,0,0,0,1},
|
||||
{ 0,1,0,1,0},
|
||||
{ 0,1,0,1,0},
|
||||
{ 0,0,1,0,0},
|
||||
{ 0,1,0,1,0},
|
||||
{ 0,1,0,1,0},
|
||||
{ 1,0,0,0,1}};
|
||||
|
||||
byte four[7][5] = {
|
||||
{ 1,0,0,0,1},
|
||||
{ 0,1,0,1,0},
|
||||
{ 0,1,0,1,0},
|
||||
{ 0,0,1,0,0},
|
||||
{ 0,1,0,1,0},
|
||||
{ 0,1,0,1,0},
|
||||
{ 1,0,0,0,1}};
|
||||
|
||||
void setup() {
|
||||
pinMode( 3, OUTPUT );
|
||||
pinMode( 9, OUTPUT );
|
||||
pinMode( 10, OUTPUT );
|
||||
pinMode( 4, OUTPUT );
|
||||
pinMode( 12, OUTPUT );
|
||||
|
||||
pinMode( 5, OUTPUT );
|
||||
pinMode( 2, OUTPUT );
|
||||
pinMode( 6, OUTPUT );
|
||||
pinMode( 11, OUTPUT );
|
||||
pinMode( 7, OUTPUT );
|
||||
pinMode( 13, OUTPUT );
|
||||
pinMode( 8, OUTPUT );
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
digitalWrite(led_row[i], 1);
|
||||
}
|
||||
for (int i = 0; i < 5; i++) {
|
||||
digitalWrite(led_col[i], 0);
|
||||
}
|
||||
|
||||
delay(500);
|
||||
draw();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
draw_task[7][5] = zero[7][5];
|
||||
// unsigned long currentTime = millis();
|
||||
//
|
||||
// if (currentTime - prevTime > interval) {
|
||||
// prevTime = currentTime;
|
||||
// draw_task[7][5] = one[7][5];
|
||||
// }
|
||||
// else {
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (int i = 0; i < 7; i++) {
|
||||
digitalWrite(led_row[i], 1);
|
||||
for (int j = 0; j < 5; j++) {
|
||||
digitalWrite(led_col[j], (draw_task[i][j] == 1 ? 0 : 1));
|
||||
}
|
||||
delayMicroseconds(900);
|
||||
digitalWrite(led_row[i], 0);
|
||||
}
|
||||
|
||||
}
|
||||
69
Projects/7x5 Display/_1.singleTets/_1.singleTets.ino
Normal file
69
Projects/7x5 Display/_1.singleTets/_1.singleTets.ino
Normal file
@@ -0,0 +1,69 @@
|
||||
int idx = 0; unsigned long last;
|
||||
|
||||
void setup() {
|
||||
last = millis();
|
||||
pinMode( 3, OUTPUT );
|
||||
pinMode( 9, OUTPUT );
|
||||
pinMode( 10, OUTPUT );
|
||||
pinMode( 4, OUTPUT );
|
||||
pinMode( 12, OUTPUT );
|
||||
|
||||
pinMode( 5, OUTPUT );
|
||||
pinMode( 2, OUTPUT );
|
||||
pinMode( 6, OUTPUT );
|
||||
pinMode( 11, OUTPUT );
|
||||
pinMode( 7, OUTPUT );
|
||||
pinMode( 13, OUTPUT );
|
||||
pinMode( 8, OUTPUT );
|
||||
|
||||
byte led[5][7] = {
|
||||
{0,0,0,0,0},
|
||||
{0,0,0,0,0},
|
||||
{0,0,0,0,0},
|
||||
{0,0,0,0,0},
|
||||
{0,0,0,0,0},
|
||||
{0,0,0,0,0},
|
||||
{0,0,0,0,0},
|
||||
}
|
||||
|
||||
byte leds[7][5];
|
||||
|
||||
void setPattern( byte pattern[20][5], int idx ) {
|
||||
for( int r =0; r < 7; r++) {
|
||||
for( int c = 0; c < 5; c++) {
|
||||
leds[r][c] = pattern[r + idx][c];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
|
||||
for( int r =0; r < 7; r ++ ) {
|
||||
digitalWrite( r + 2, HIGH );
|
||||
for( int c=0; c < 5; c ++ ) {
|
||||
digitalWrite( 13 - c, ( leds[r][c] == 1 ? LOW : HIGH ));
|
||||
}
|
||||
delayMicroseconds(900);
|
||||
digitalWrite( r + 2, LOW );
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if ( millis() - last > 400 ) {
|
||||
idx = (idx == 0 ? 7 : 0);
|
||||
last = millis();
|
||||
}
|
||||
|
||||
byte tmp[14][5] = {
|
||||
{ 1,1,1,1,1},
|
||||
{ 1,1,1,1,1},
|
||||
{ 1,1,1,1,1},
|
||||
{ 1,1,1,1,1},
|
||||
{ 1,1,1,1,1},
|
||||
{ 1,1,1,1,1},
|
||||
{ 1,1,1,1,1},
|
||||
};
|
||||
|
||||
setPattern( tmp, idx );
|
||||
draw();
|
||||
}
|
||||
78
Projects/Colorful_Light_RGB_LEDs/Colorful_Light_RGB_LEDs.ino
Executable file
78
Projects/Colorful_Light_RGB_LEDs/Colorful_Light_RGB_LEDs.ino
Executable file
@@ -0,0 +1,78 @@
|
||||
/* ---------------------------------------------------------
|
||||
* | Experimentation Kit for Arduino Example Code |
|
||||
* | CIRC-RGB .: Colourful Light :. (RGB LED) |
|
||||
* ---------------------------------------------------------
|
||||
*
|
||||
* We've blinked an LED and controlled eight in sequence now it's time to
|
||||
* control colour. Using an RGB LED (actual 3 LEDs in a single housing)
|
||||
* we can generate any colour our heart desires.
|
||||
*
|
||||
* (we'll also use a few programming shortcuts to make the code
|
||||
* more portable/readable)
|
||||
*/
|
||||
|
||||
|
||||
//RGB LED pins
|
||||
int ledDigitalOne[] = {9, 10, 11}; //the three digital pins of the digital LED
|
||||
//9 = redPin, 10 = greenPin, 11 = bluePin
|
||||
|
||||
const boolean ON = LOW; //Define on as LOW (this is because we use a common
|
||||
//Anode RGB LED (common pin is connected to +5 volts)
|
||||
const boolean OFF = HIGH; //Define off as HIGH
|
||||
|
||||
//Predefined Colors
|
||||
const boolean RED[] = {ON, OFF, OFF};
|
||||
const boolean BLUE[] = {OFF, ON, OFF};
|
||||
const boolean GREEN[] = {OFF, OFF, ON};
|
||||
const boolean YELLOW[] = {ON, OFF, ON};
|
||||
const boolean CYAN[] = {OFF, ON, ON};
|
||||
const boolean MAGENTA[] = {ON, ON, OFF};
|
||||
const boolean WHITE[] = {ON, ON, ON};
|
||||
const boolean BLACK[] = {OFF, OFF, OFF};
|
||||
|
||||
//An Array that stores the predefined colors (allows us to later randomly display a color)
|
||||
const boolean* COLORS[] = {RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA, WHITE, BLACK};
|
||||
|
||||
void setup(){
|
||||
for(int i = 0; i < 3; i++){
|
||||
pinMode(ledDigitalOne[i], OUTPUT); //Set the three LED pins as outputs
|
||||
}
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
/* Example - 1 Set a color
|
||||
Set the three LEDs to any predefined color
|
||||
*/
|
||||
setColor(ledDigitalOne, RED); //Set the color of LED one
|
||||
|
||||
|
||||
/* Example - 2 Go through Random Colors
|
||||
Set the LEDs to a random color
|
||||
*/
|
||||
randomColor();
|
||||
|
||||
}
|
||||
|
||||
void randomColor(){
|
||||
int rand = random(0, sizeof(COLORS) / 2); //get a random number within the range of colors
|
||||
setColor(ledDigitalOne, COLORS[rand]); //Set the color of led one to a random color
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
/* Sets an led to any color
|
||||
led - a three element array defining the three color pins (led[0] = redPin, led[1] = greenPin, led[2] = bluePin)
|
||||
color - a three element boolean array (color[0] = red value (LOW = on, HIGH = off), color[1] = green value, color[2] =blue value)
|
||||
*/
|
||||
void setColor(int* led, boolean* color){
|
||||
for(int i = 0; i < 3; i++){
|
||||
digitalWrite(led[i], color[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* A version of setColor that allows for using const boolean colors
|
||||
*/
|
||||
void setColor(int* led, const boolean* color){
|
||||
boolean tempColor[] = {color[0], color[1], color[2]};
|
||||
setColor(led, tempColor);
|
||||
}
|
||||
39
Projects/I2C_20x4_Test/I2C_20x4_Test/I2C_20x4_Test.ino
Normal file
39
Projects/I2C_20x4_Test/I2C_20x4_Test/I2C_20x4_Test.ino
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <Wire.h>
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
|
||||
#define I2C_ADDR 0x3F
|
||||
#define En_pin 2
|
||||
#define Rw_pin 5
|
||||
#define Rs_pin 4
|
||||
#define D4_pin 0
|
||||
#define D5_pin 1
|
||||
#define D6_pin 6
|
||||
#define D7_pin 7
|
||||
#define BACKLIGHT_PIN 3
|
||||
|
||||
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin,
|
||||
D4_pin, D5_pin, D6_pin, D7_pin);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
lcd.begin (20, 4);
|
||||
|
||||
// Switch on the backlight
|
||||
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
|
||||
lcd.setBacklight(HIGH);
|
||||
|
||||
// Position cursor and write some text
|
||||
lcd.print("Poop in face");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.available()) {
|
||||
lcd.clear();
|
||||
lcd.home();
|
||||
while(Serial.available() > 0) {
|
||||
lcd.print(Serial.read());
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
92
Projects/IR_LightSwitch/IR_LightSwitch.ino
Executable file
92
Projects/IR_LightSwitch/IR_LightSwitch.ino
Executable file
@@ -0,0 +1,92 @@
|
||||
#include <IRremote.h>
|
||||
#include <Servo.h>
|
||||
|
||||
Servo myservo;
|
||||
int pos = 0;
|
||||
int RECV_PIN = 11;
|
||||
IRrecv irrecv(RECV_PIN);
|
||||
decode_results results;
|
||||
unsigned long CurrentValue = 0;
|
||||
unsigned long StoredCode = 0;
|
||||
const int buttonPin = 6; // the number of the pushbutton pin
|
||||
const int ledPin = 4; // the number of the LED pin
|
||||
const int outputPin = 3; // the number of the output LED pin
|
||||
const int relayPin = 2; // the number of the relay pin
|
||||
int buttonState = 0; // variable for reading the pushbutton status
|
||||
int RecordState = 0; //is the reciever in record mode
|
||||
int outputState = 1; //is the output on or off
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
myservo.attach(9);
|
||||
irrecv.enableIRIn(); // Start the receiver
|
||||
|
||||
// initialize the LED pin as an output:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
// initialize the pushbutton pin as an input:
|
||||
pinMode(outputPin, OUTPUT);
|
||||
// initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT);
|
||||
pinMode(relayPin, OUTPUT);
|
||||
// initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
// read the state of the pushbutton value:
|
||||
buttonState = digitalRead(buttonPin);
|
||||
|
||||
// if a signal is detected, store the value
|
||||
if (irrecv.decode(&results)) {
|
||||
CurrentValue = (results.value);
|
||||
|
||||
// if the recieved value equals the programed value, then toggle the output state
|
||||
if(CurrentValue == StoredCode) {
|
||||
outputState = 1;
|
||||
}
|
||||
|
||||
// if the record mode is activated store the current value as the programed value
|
||||
if (RecordState == 1) {
|
||||
StoredCode = CurrentValue;
|
||||
RecordState = 0;
|
||||
digitalWrite(ledPin, LOW);
|
||||
Serial.println(StoredCode); //displays stored code for reference
|
||||
}
|
||||
|
||||
// Receive the next value
|
||||
irrecv.resume();
|
||||
}
|
||||
|
||||
else //if no signal is detected, then the current value is 0
|
||||
{
|
||||
CurrentValue = 0;
|
||||
}
|
||||
|
||||
// check if the record button is pressed.
|
||||
// if it is, the buttonState is HIGH:
|
||||
if (buttonState == HIGH) {
|
||||
|
||||
//wait for the button to be released
|
||||
while (buttonState == HIGH) {
|
||||
buttonState = digitalRead(buttonPin);
|
||||
}
|
||||
|
||||
//turn on the LED to indicate that record mode is on
|
||||
digitalWrite(ledPin, HIGH);
|
||||
RecordState = 1;
|
||||
}
|
||||
|
||||
//set the appropriate output state
|
||||
if(outputState == 1) {
|
||||
|
||||
digitalWrite(outputPin, HIGH);
|
||||
myservo.write(180);
|
||||
delay(1000);
|
||||
myservo.write(150);
|
||||
digitalWrite(outputPin, LOW);
|
||||
outputState = 0;
|
||||
}
|
||||
|
||||
}
|
||||
22
Projects/Keyboard/Login/Login.ino
Executable file
22
Projects/Keyboard/Login/Login.ino
Executable file
@@ -0,0 +1,22 @@
|
||||
const int buttonPin = 4;
|
||||
int buttonState = LOW;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(buttonPin, LOW);
|
||||
Keyboard.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int buttonState = digitalRead(buttonPin);
|
||||
if (buttonState == HIGH)
|
||||
{
|
||||
Keyboard.write((char) 0xB0);
|
||||
delay(500);
|
||||
Keyboard.print("Kevinojm");
|
||||
Keyboard.write((char) 0xB0);
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
24
Projects/Keyboard/Open_Program/Open_Program.ino
Executable file
24
Projects/Keyboard/Open_Program/Open_Program.ino
Executable file
@@ -0,0 +1,24 @@
|
||||
const int buttonPin = 4;
|
||||
int buttonState = LOW;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(buttonPin, LOW);
|
||||
Keyboard.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int buttonState = digitalRead(buttonPin);
|
||||
if (buttonState == HIGH)
|
||||
{
|
||||
Keyboard.press((char) 0x80);
|
||||
Keyboard.press((char) 0x20);
|
||||
Keyboard.releaseAll();
|
||||
Keyboard.print("Photoshop");
|
||||
Keyboard.write((char) 0xB0);
|
||||
Keyboard.releaseAll();
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
24
Projects/Keyboard/Sleep/Sleep.ino
Executable file
24
Projects/Keyboard/Sleep/Sleep.ino
Executable file
@@ -0,0 +1,24 @@
|
||||
const int buttonPin = 4;
|
||||
int buttonState = LOW;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(buttonPin, LOW);
|
||||
Keyboard.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int buttonState = digitalRead(buttonPin);
|
||||
if (buttonState == HIGH)
|
||||
{
|
||||
Keyboard.press((char) 0x80);
|
||||
Keyboard.press((char) 0x20);
|
||||
Keyboard.releaseAll();
|
||||
delay(100);
|
||||
Keyboard.print("Sleep");
|
||||
Keyboard.write((char) 0xB0);
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
28
Projects/Keyboard/ping/ping.ino
Executable file
28
Projects/Keyboard/ping/ping.ino
Executable file
@@ -0,0 +1,28 @@
|
||||
const int buttonPin = 4;
|
||||
int buttonState = LOW;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(buttonPin, LOW);
|
||||
Keyboard.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int buttonState = digitalRead(buttonPin);
|
||||
if (buttonState == HIGH)
|
||||
{
|
||||
Keyboard.press((char) 0x80);
|
||||
Keyboard.press((char) 0x20);
|
||||
Keyboard.releaseAll();
|
||||
delay(100);
|
||||
Keyboard.print("Terminal");
|
||||
Keyboard.write((char) 0xB0);
|
||||
delay(600);
|
||||
Keyboard.print("ping google.com");
|
||||
Keyboard.write((char) 0xB0);
|
||||
Keyboard.releaseAll();
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
104
Projects/Lock/Lock.ino
Executable file
104
Projects/Lock/Lock.ino
Executable file
@@ -0,0 +1,104 @@
|
||||
// Keypad_Lock.ino
|
||||
#include <Servo.h>
|
||||
#include <Keypad.h>
|
||||
|
||||
// Output
|
||||
int led = 2;
|
||||
|
||||
// Input
|
||||
char passphrase[] = {'1', '2', '3', '4'};
|
||||
int pass_length = sizeof(passphrase);
|
||||
bool locked = true;
|
||||
int i = 0;
|
||||
int angle = 0;
|
||||
|
||||
const byte rows = 4;
|
||||
const byte cols = 3;
|
||||
char keys[rows][cols] = {
|
||||
{'1', '2', '3'},
|
||||
{'4', '5', '6'},
|
||||
{'7', '8', '9'},
|
||||
{'*', '0', '#'}
|
||||
};
|
||||
|
||||
byte rowPins[rows] = {9, 8, 7, 6};
|
||||
byte colPins[cols] = {5, 4, 3};
|
||||
|
||||
Servo myservo;
|
||||
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
|
||||
|
||||
void unlock() {
|
||||
locked = false;
|
||||
|
||||
for(int i=0; i<5; i++) {
|
||||
digitalWrite(led, HIGH);
|
||||
delay(250);
|
||||
digitalWrite(led, LOW);
|
||||
delay(250);
|
||||
}
|
||||
|
||||
myservo.write(160);
|
||||
}
|
||||
|
||||
void lock() {
|
||||
locked = true;
|
||||
i = 0;
|
||||
|
||||
myservo.write(40);
|
||||
}
|
||||
|
||||
void correct_entry() {
|
||||
i++;
|
||||
|
||||
if (i!=pass_length) {
|
||||
//digitalWrite(led, HIGH);
|
||||
//delay(250);
|
||||
//digitalWrite(led, LOW);
|
||||
}
|
||||
else {
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// Output
|
||||
pinMode(led, OUTPUT);
|
||||
myservo.attach(10, 0, 2000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
char key = keypad.getKey();
|
||||
|
||||
if (key) {
|
||||
// Debug
|
||||
Serial.print(key);
|
||||
Serial.println(passphrase[i]);
|
||||
|
||||
// key_pressed();
|
||||
|
||||
if (locked==false) {
|
||||
if (key=='*') {
|
||||
lock();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (i==0) {
|
||||
if (key==passphrase[i]) {
|
||||
correct_entry();
|
||||
}
|
||||
}
|
||||
else if (i>0) {
|
||||
if (key==passphrase[i]) {
|
||||
correct_entry();
|
||||
}
|
||||
else {
|
||||
i=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
25
Projects/ProgLab/Instrument/Instrument.ino
Normal file
25
Projects/ProgLab/Instrument/Instrument.ino
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <Servo.h>
|
||||
|
||||
Servo myservo;
|
||||
|
||||
int potpin = 0;
|
||||
int potReading;
|
||||
int photocellPin = 1;
|
||||
int photocellReading;
|
||||
|
||||
void setup()
|
||||
{
|
||||
myservo.attach(9);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
potReading = analogRead(potpin);
|
||||
potReading = map(potReading, 0, 1023, 0, 179);
|
||||
myservo.write(potReading);
|
||||
photocellReading = analogRead(photocellPin);
|
||||
|
||||
int thisPitch = map(photocellReading, 1, 1000, 120, 1500);
|
||||
tone(8, thisPitch, 10);
|
||||
delay(1);
|
||||
}
|
||||
1
Projects/ProgLab/Instrument2/Instrument2.ino
Normal file
1
Projects/ProgLab/Instrument2/Instrument2.ino
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
107
Projects/ProgLab/LineFollow/LineFollow.ino
Normal file
107
Projects/ProgLab/LineFollow/LineFollow.ino
Normal file
@@ -0,0 +1,107 @@
|
||||
#include <PLab_ZumoMotors.h>
|
||||
#include <Pushbutton.h>
|
||||
#include <QTRSensors.h>
|
||||
#include <ZumoBuzzer.h>
|
||||
#include <ZumoMotors.h>
|
||||
#include <ZumoReflectanceSensorArray.h>
|
||||
|
||||
|
||||
/*
|
||||
* Demo line-following code for the Pololu Zumo Robot
|
||||
*
|
||||
* This code will follow a black line on a white background, using a
|
||||
* PID-based algorithm. It works decently on courses with smooth, 6"
|
||||
* radius curves and has been tested with Zumos using 30:1 HP and
|
||||
* 75:1 HP motors. Modifications might be required for it to work
|
||||
* well on different courses or with different motors.
|
||||
*
|
||||
* http://www.pololu.com/catalog/product/2506
|
||||
* http://www.pololu.com
|
||||
* http://forum.pololu.com
|
||||
*/
|
||||
|
||||
|
||||
ZumoReflectanceSensorArray reflectanceSensors;
|
||||
ZumoMotors motors;
|
||||
Pushbutton button(ZUMO_BUTTON);
|
||||
int lastError = 0;
|
||||
|
||||
// This is the maximum speed the motors will be allowed to turn.
|
||||
// (400 lets the motors go at top speed; decrease to impose a speed limit)
|
||||
const int MAX_SPEED = 400;
|
||||
// Set constants for PID control
|
||||
const float KP = 0.5; // Proportional constant
|
||||
const float KD = 6; // Derivative constant
|
||||
const int SV = 2500; // Set-value for position (in the middle of sensors)
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
reflectanceSensors.init();
|
||||
button.waitForButton(); // wait to start calibration
|
||||
|
||||
// Turn on LED to indicate we are in calibration mode
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, HIGH);
|
||||
|
||||
// Wait 1 second and then begin automatic sensor calibration
|
||||
// by rotating in place to sweep the sensors over the line
|
||||
delay(1000);
|
||||
int i;
|
||||
for(i = 0; i < 80; i++)
|
||||
{
|
||||
if ((i > 10 && i <= 30) || (i > 50 && i <= 70))
|
||||
motors.setSpeeds(-200, 200);
|
||||
else
|
||||
motors.setSpeeds(200, -200);
|
||||
|
||||
reflectanceSensors.calibrate();
|
||||
|
||||
// Since our counter runs to 80, the total delay will be
|
||||
// 80*20 = 1600 ms.
|
||||
delay(20);
|
||||
}
|
||||
motors.setSpeeds(0,0);
|
||||
|
||||
// Turn off LED to indicate we are through with calibration
|
||||
digitalWrite(13, LOW);
|
||||
|
||||
// Wait for the user button to be pressed and released
|
||||
button.waitForButton();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
unsigned int sensors[6];
|
||||
|
||||
int pv = reflectanceSensors.readLine(sensors);
|
||||
// Our "error" is how far we are away from the center of the line, which
|
||||
// corresponds to position 2500.
|
||||
int error = pv - SV;
|
||||
// do PD computation ( Integral is not used)
|
||||
int speedDifference = KP*error + KD * (error - lastError);
|
||||
|
||||
lastError = error;
|
||||
|
||||
// Get individual motor speeds. The sign of speedDifference
|
||||
// determines if the robot turns left or right.
|
||||
int m1Speed = MAX_SPEED + speedDifference;
|
||||
int m2Speed = MAX_SPEED - speedDifference;
|
||||
|
||||
// Here we constrain our motor speeds to be between 0 and MAX_SPEED.
|
||||
// Generally speaking, one motor will always be turning at MAX_SPEED
|
||||
// and the other will be at MAX_SPEED-|speedDifference| if that is positive,
|
||||
// else it will be stationary. For some applications, you might want to
|
||||
// allow the motor speed to go negative so that it can spin in reverse.
|
||||
if (m1Speed < 0)
|
||||
m1Speed = 0;
|
||||
if (m2Speed < 0)
|
||||
m2Speed = 0;
|
||||
if (m1Speed > MAX_SPEED)
|
||||
m1Speed = MAX_SPEED;
|
||||
if (m2Speed > MAX_SPEED)
|
||||
m2Speed = MAX_SPEED;
|
||||
|
||||
motors.setSpeeds(m1Speed, m2Speed);
|
||||
}
|
||||
53
Projects/ProgLab/LineFollower/LineFollower.ino
Normal file
53
Projects/ProgLab/LineFollower/LineFollower.ino
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <PLab_ZumoMotors.h>
|
||||
#include <Pushbutton.h>
|
||||
#include <QTRSensors.h>
|
||||
#include <ZumoBuzzer.h>
|
||||
#include <ZumoMotors.h>
|
||||
#include <ZumoReflectanceSensorArray.h>
|
||||
|
||||
#define driveSpeed 150
|
||||
#define lightThreshold 800
|
||||
|
||||
ZumoMotors motors;
|
||||
Pushbutton button(ZUMO_BUTTON);
|
||||
unsigned int sensorValues[6];
|
||||
ZumoReflectanceSensorArray reflectanceSensors;
|
||||
|
||||
void setup()
|
||||
{
|
||||
reflectanceSensors.init();
|
||||
motors.setSpeeds(0,0);
|
||||
button.waitForButton();
|
||||
}
|
||||
|
||||
void findLine()
|
||||
{
|
||||
reflectanceSensors.read(sensorValues);
|
||||
if (sensorValues[0] > lightThreshold)
|
||||
{
|
||||
turnLeft();
|
||||
}
|
||||
else if (sensorValues[5] > lightThreshold)
|
||||
{
|
||||
turnRight();
|
||||
}
|
||||
}
|
||||
|
||||
void turnLeft()
|
||||
{
|
||||
motors.setSpeeds(-driveSpeed, -300);
|
||||
delay(400);
|
||||
}
|
||||
void turnRight()
|
||||
{
|
||||
motors.setSpeeds(-300, -driveSpeed);
|
||||
delay(400);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
findLine();
|
||||
motors.setSpeeds(driveSpeed, driveSpeed);
|
||||
}
|
||||
|
||||
|
||||
57
Projects/ProgLab/Lyskryss/Lyskryss.ino
Normal file
57
Projects/ProgLab/Lyskryss/Lyskryss.ino
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <Servo.h>
|
||||
#include <NewPing.h>
|
||||
|
||||
#define Trigger_Pin 12
|
||||
#define Echo_Pin 11
|
||||
#define Max_Distance 200
|
||||
|
||||
// Green car - 10
|
||||
// Yellow car - 9
|
||||
// Red car - 8
|
||||
// Green person - 7
|
||||
// Red person - 6
|
||||
// ECHO 11 & 12
|
||||
|
||||
|
||||
NewPing sonar(Trigger_Pin, Echo_Pin, Max_Distance);
|
||||
|
||||
Servo gateServo;
|
||||
int servoPos = 0;
|
||||
|
||||
int lightPinArray[] = {
|
||||
10, 9, 9, 8, 7, 6, 6, 7, 9, 8, 9};
|
||||
boolean lightStateArray[] = {
|
||||
LOW, HIGH, LOW, HIGH, LOW, HIGH, LOW, HIGH, HIGH, LOW, LOW};
|
||||
int lightDelayArray[] = {
|
||||
1000, 0, 500, 0, 500, 0, 2000, 0, 500, 500, 0};
|
||||
|
||||
void setup()
|
||||
{
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
pinMode(i + 6, OUTPUT);
|
||||
}
|
||||
gateServo.attach(4);
|
||||
}
|
||||
|
||||
void personDetected()
|
||||
{
|
||||
for(int i = 0; i < 12; i++)
|
||||
{
|
||||
delay(lightDelayArray[i]);
|
||||
digitalWrite(lightPinArray[i], lightStateArray[i]);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
unsigned int uS = sonar.ping();
|
||||
if ((uS /US_ROUNDTRIP_CM) < 5 && uS /US_ROUNDTRIP_CM > 1)
|
||||
{
|
||||
personDetected();
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(7, HIGH);
|
||||
digitalWrite(10, HIGH);
|
||||
}
|
||||
}
|
||||
BIN
Projects/ProgLab/Lyskryss/data/plab-library-master.zip
Normal file
BIN
Projects/ProgLab/Lyskryss/data/plab-library-master.zip
Normal file
Binary file not shown.
89
Projects/ProgLab/Zumo_1/Zumo_1.ino
Normal file
89
Projects/ProgLab/Zumo_1/Zumo_1.ino
Normal file
@@ -0,0 +1,89 @@
|
||||
#include <PLab_ZumoMotors.h>
|
||||
#include <Pushbutton.h>
|
||||
#include <QTRSensors.h>
|
||||
#include <ZumoBuzzer.h>
|
||||
#include <ZumoMotors.h>
|
||||
#include <ZumoReflectanceSensorArray.h>
|
||||
|
||||
ZumoReflectanceSensorArray reflectanceSensors;
|
||||
unsigned int sensor_values[6];
|
||||
ZumoMotors motors;
|
||||
Pushbutton button(ZUMO_BUTTON);
|
||||
int lastError = 0;
|
||||
|
||||
const int MAX_SPEED = 800;
|
||||
// Set constants for PID control
|
||||
const float KP = 0.5; // Proportional constant
|
||||
const float KD = 6; // Derivative constant
|
||||
const int SV = 2500; // Set-value for position (in the middle of sensors)
|
||||
|
||||
unsigned long Timer; //"ALWAYS use unsigned long for timers, not int"
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
reflectanceSensors.init();
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, HIGH);
|
||||
button.waitForButton();
|
||||
for(int i = 0; i < 80; i++)
|
||||
{
|
||||
if ((i > 10 && i <= 30) || (i > 50 && i <= 70))
|
||||
motors.setSpeeds(-200, 200);
|
||||
else
|
||||
motors.setSpeeds(200, -200);
|
||||
|
||||
reflectanceSensors.calibrate();
|
||||
|
||||
// Since our counter runs to 80, the total delay will be
|
||||
// 80*20 = 1600 ms.
|
||||
delay(20);
|
||||
}
|
||||
motors.setSpeeds(0, 0);
|
||||
button.waitForButton();
|
||||
|
||||
digitalWrite(13, LOW);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
reflectanceSensors.read(sensor_values);
|
||||
if (sensor_values[5] < 1800)
|
||||
{
|
||||
motors.setSpeeds(-100, -100);
|
||||
delay(1000);
|
||||
motors.setSpeeds(-100, 100);
|
||||
delay(1000);
|
||||
}
|
||||
else if (sensor_values[0] < 1800)
|
||||
{
|
||||
motors.setSpeeds(-100, -100);
|
||||
delay(1000);
|
||||
motors.setSpeeds(100, -100);
|
||||
delay(1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
motors.setSpeeds(100, 100);
|
||||
}
|
||||
|
||||
int pv = reflectanceSensors.readLine(sensor_values);
|
||||
// Our "error" is how far we are away from the center of the line, which
|
||||
// corresponds to position 2500.
|
||||
int error = pv - SV;
|
||||
// do PD computation ( Integral is not used)
|
||||
int speedDifference = KP*error + KD * (error - lastError);
|
||||
|
||||
|
||||
//Serial.println(error);
|
||||
lastError = error;
|
||||
|
||||
// Get individual motor speeds. The sign of speedDifference
|
||||
// determines if the robot turns left or right.
|
||||
int m1Speed = MAX_SPEED + speedDifference;
|
||||
int m2Speed = MAX_SPEED - speedDifference;
|
||||
|
||||
|
||||
|
||||
motors.setSpeeds(m1Speed, m2Speed);
|
||||
}
|
||||
54
Projects/ProgLab/Zumo_2.0/Zumo_2.0.ino
Normal file
54
Projects/ProgLab/Zumo_2.0/Zumo_2.0.ino
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <PLab_ZumoMotors.h>
|
||||
#include <Pushbutton.h>
|
||||
#include <QTRSensors.h>
|
||||
#include <ZumoBuzzer.h>
|
||||
#include <ZumoMotors.h>
|
||||
#include <ZumoReflectanceSensorArray.h>
|
||||
|
||||
#define maxSpeed 400
|
||||
#define reverseSpeed 400
|
||||
#define lightThreshold 1800
|
||||
|
||||
ZumoMotors motors;
|
||||
Pushbutton button(ZUMO_BUTTON);
|
||||
unsigned int sensorValues[6];
|
||||
ZumoReflectanceSensorArray reflectaneceSensors;
|
||||
|
||||
void setup()
|
||||
{
|
||||
reflectaneceSensors.init();
|
||||
motors.setSpeeds(0,0);
|
||||
button.waitForButton();
|
||||
}
|
||||
|
||||
void findLine()
|
||||
{
|
||||
reflectaneceSensors.read(sensorValues);
|
||||
if (sensorValues[0] > lightThreshold)
|
||||
{
|
||||
turnLeft(1000);
|
||||
}
|
||||
else if (sensorValues[5] > lightThreshold)
|
||||
{
|
||||
turnRight(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void turnLeft(int delayTime)
|
||||
{
|
||||
motors.setSpeeds(0, 200);
|
||||
delay(delayTime);
|
||||
}
|
||||
void turnRight(int delayTime)
|
||||
{
|
||||
motors.setSpeeds(200, 0);
|
||||
delay(delayTime);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
findLine();
|
||||
motors.setSpeeds(200, 200);
|
||||
}
|
||||
|
||||
|
||||
81
Projects/ProgLab/Zumo_2/Zumo_2.ino
Normal file
81
Projects/ProgLab/Zumo_2/Zumo_2.ino
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
Drive forward and turn left or right when border is detected
|
||||
- Only reflectionsensor 0 and 5 are used.
|
||||
*/
|
||||
#include <ZumoMotors.h>
|
||||
#include <Pushbutton.h>
|
||||
#include <QTRSensors.h>
|
||||
#include <ZumoReflectanceSensorArray.h>
|
||||
#include <NewPing.h>
|
||||
|
||||
#define LED 13
|
||||
|
||||
// this might need to be tuned for different lighting conditions, surfaces, etc.
|
||||
#define lightThreshold 1800 //
|
||||
|
||||
#define reverseSpeed 200
|
||||
#define turnSpeed 200
|
||||
#define forwardSpeed 100
|
||||
#define revDuration 200
|
||||
#define turnDuration 500
|
||||
ZumoMotors motors;
|
||||
Pushbutton button(ZUMO_BUTTON); // pushbutton on pin 12
|
||||
#define NUM_SENSORS 6
|
||||
unsigned int sensor_values[NUM_SENSORS];
|
||||
ZumoReflectanceSensorArray sensors;
|
||||
|
||||
const int echoPin1 = 2;
|
||||
const int echoPin2 = 4;
|
||||
const int triggerPin1 = 3;
|
||||
const int triggerPin2 = 5;
|
||||
const int maxDistance = 40;
|
||||
|
||||
NewPing sonar1(triggerPin1, echoPin1, maxDistance);
|
||||
NewPing sonar2(triggerPin2, echoPin2, maxDistance);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
sensors.init();
|
||||
button.waitForButton();
|
||||
}
|
||||
|
||||
void turnLeft()
|
||||
{
|
||||
motors.setSpeeds(-reverseSpeed, -reverseSpeed);
|
||||
delay(revDuration);
|
||||
motors.setSpeeds(turnSpeed, -turnSpeed);
|
||||
delay(turnDuration);
|
||||
motors.setSpeeds(forwardSpeed, forwardSpeed);
|
||||
}
|
||||
|
||||
void turnRight()
|
||||
{
|
||||
motors.setSpeeds(-reverseSpeed, -reverseSpeed);
|
||||
delay(revDuration);
|
||||
motors.setSpeeds(-turnSpeed, turnSpeed);
|
||||
delay(turnDuration);
|
||||
motors.setSpeeds(forwardSpeed, forwardSpeed);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
sensors.read(sensor_values);
|
||||
if (sensor_values[0] < lightThresHold || sensor_values[5] < lightThreshold)
|
||||
{
|
||||
if (sensor_values[0] < lightThreshold)
|
||||
{
|
||||
turnLeft();
|
||||
}
|
||||
else if (sensor_values[5] < lightThreshold)
|
||||
{
|
||||
turnRight();
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int time = sonar1.ping();
|
||||
if (
|
||||
|
||||
// If haven't done anything, go forward
|
||||
motors.setSpeeds(forwardSpeed, forwardSpeed);
|
||||
}
|
||||
128
Projects/ProgLab/Zumo__/Zumo__.ino
Normal file
128
Projects/ProgLab/Zumo__/Zumo__.ino
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
Drive forward and turn left or right when border is detected
|
||||
- Only reflectionsensor 0 and 5 are used.
|
||||
*/
|
||||
#include <ZumoMotors.h>
|
||||
#include <Pushbutton.h>
|
||||
#include <QTRSensors.h>
|
||||
#include <ZumoReflectanceSensorArray.h>
|
||||
#include <NewPing.h>
|
||||
|
||||
#define LED 13
|
||||
|
||||
// this might need to be tuned for different lighting conditions, surfaces, etc.
|
||||
#define lightThreshold 1800 //
|
||||
|
||||
#define reverseSpeed 400
|
||||
#define turnSpeed 400
|
||||
#define forwardSpeed 400
|
||||
#define revDuration 300
|
||||
#define turnDuration 200
|
||||
#define triggerPin 3
|
||||
#define echoPin 2
|
||||
#define maxDistance 200
|
||||
|
||||
ZumoMotors motors;
|
||||
Pushbutton button(ZUMO_BUTTON); // pushbutton on pin 12
|
||||
#define NUM_SENSORS 6
|
||||
unsigned int sensor_values[NUM_SENSORS];
|
||||
ZumoReflectanceSensorArray sensors;
|
||||
|
||||
NewPing sonar(triggerPin, echoPin, maxDistance);
|
||||
|
||||
unsigned int pingSpeed = 100;
|
||||
unsigned long pingTimer;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
sensors.init();
|
||||
pingTimer = millis();
|
||||
//button.waitForButton();
|
||||
}
|
||||
|
||||
boolean findLine()
|
||||
{
|
||||
sensors.read(sensor_values);
|
||||
if (sensor_values[0] < lightThreshold || sensor_values[5] < lightThreshold)
|
||||
{
|
||||
if (sensor_values[0] < lightThreshold)
|
||||
{
|
||||
turnLeft();
|
||||
return true;
|
||||
}
|
||||
else if (sensor_values[5] < lightThreshold)
|
||||
{
|
||||
turnRight();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void turnLeft()
|
||||
{
|
||||
motors.setSpeeds(-reverseSpeed, -reverseSpeed);
|
||||
delay(revDuration);
|
||||
motors.setSpeeds(turnSpeed, -turnSpeed);
|
||||
delay(turnDuration);
|
||||
}
|
||||
|
||||
void turnRight()
|
||||
{
|
||||
motors.setSpeeds(-reverseSpeed, -reverseSpeed);
|
||||
delay(revDuration);
|
||||
motors.setSpeeds(-turnSpeed, turnSpeed);
|
||||
delay(turnDuration);
|
||||
}
|
||||
/*
|
||||
void search()
|
||||
{
|
||||
time = sonar.ping();
|
||||
distance = sonar.convert_cm(time);
|
||||
if (distance < 40)
|
||||
motors.setSpeeds(310, 400);
|
||||
else
|
||||
{
|
||||
motors.setSpeeds(400, 400);
|
||||
delay(20);
|
||||
time = sonar.ping();
|
||||
distance = sonar.convert_cm(time);
|
||||
if (distance < 40)
|
||||
motors.setSpeeds(310, 400);
|
||||
}
|
||||
}*/
|
||||
|
||||
void echoCheck()
|
||||
{
|
||||
if (sonar.check_timer())
|
||||
{
|
||||
if (sonar.ping_result / US_ROUNDTRIP_CM < 20)
|
||||
{
|
||||
Serial.println(sonar.ping_result / US_ROUNDTRIP_CM);
|
||||
motors.setSpeeds(310, 400);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Nothing here!");
|
||||
motors.setSpeeds(400, 400);
|
||||
delay(20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void scan()
|
||||
{
|
||||
// Init at start, find the target.
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
findLine();
|
||||
motors.setSpeeds(310, 400);
|
||||
if (millis() >= pingTimer)
|
||||
{
|
||||
pingTimer += pingSpeed;
|
||||
sonar.ping_timer(echoCheck);
|
||||
}
|
||||
}
|
||||
221
Projects/ProgLab/toneAC.h/toneAC.h
Normal file
221
Projects/ProgLab/toneAC.h/toneAC.h
Normal file
@@ -0,0 +1,221 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// toneAC Library - v1.2 - 01/27/2013
|
||||
|
||||
//
|
||||
|
||||
// AUTHOR/LICENSE:
|
||||
|
||||
// Created by Tim Eckel - teckel@leethost.com
|
||||
|
||||
// Copyright 2013 License: GNU GPL v3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
//
|
||||
|
||||
// LINKS:
|
||||
|
||||
// Project home: http://code.google.com/p/arduino-tone-ac/
|
||||
|
||||
// Blog: http://arduino.cc/forum/index.php/topic,142097.msg1066968.html
|
||||
|
||||
//
|
||||
|
||||
// DISCLAIMER:
|
||||
|
||||
// This software is furnished "as is", without technical support, and with no
|
||||
|
||||
// warranty, express or implied, as to its usefulness for any purpose.
|
||||
|
||||
//
|
||||
|
||||
// PURPOSE:
|
||||
|
||||
// Replacement to the standard tone library with the advantage of nearly twice
|
||||
|
||||
// the volume, higher frequencies (even if running at a lower clock speed),
|
||||
|
||||
// higher quality (less clicking), nearly 1.5k smaller compiled code and less
|
||||
|
||||
// stress on the speaker. Disadvantages are that it must use certain pins and
|
||||
|
||||
// it uses two pins instead of one. But, if you're flexible with your pin
|
||||
|
||||
// choices, this is a great upgrade. It also uses timer 1 instead of timer 2,
|
||||
|
||||
// which may free up a conflict you have with the tone library. It exclusively
|
||||
|
||||
// uses port registers for the fastest and smallest code possible.
|
||||
|
||||
//
|
||||
|
||||
// USAGE:
|
||||
|
||||
// Connection is very similar to a piezo or standard speaker. Except, instead
|
||||
|
||||
// of connecting one speaker wire to ground you connect both speaker wires to
|
||||
|
||||
// Arduino pins. The pins you connect to are specific, as toneAC lets the
|
||||
|
||||
// ATmega microcontroller do all the pin timing and switching. This is
|
||||
|
||||
// important due to the high switching speed possible with toneAC and to make
|
||||
|
||||
// sure the pins are alyways perfectly out of phase with each other
|
||||
|
||||
// (push/pull). See the below CONNECTION section for which pins to use for
|
||||
|
||||
// different Arduinos. Just as usual when connecting a speaker, make sure you
|
||||
|
||||
// add an inline 100 ohm resistor between one of the pins and the speaker wire.
|
||||
|
||||
//
|
||||
|
||||
// CONNECTION:
|
||||
|
||||
// Pins 9 & 10 - ATmega328, ATmega128, ATmega640, ATmega8, Uno, Leonardo, etc.
|
||||
|
||||
// Pins 11 & 12 - ATmega2560/2561, ATmega1280/1281, Mega
|
||||
|
||||
// Pins 12 & 13 - ATmega1284P, ATmega644
|
||||
|
||||
// Pins 14 & 15 - Teensy 2.0
|
||||
|
||||
// Pins 25 & 26 - Teensy++ 2.0
|
||||
|
||||
//
|
||||
|
||||
// SYNTAX:
|
||||
|
||||
// toneAC( frequency [, volume [, length [, background ]]] ) - Play a note.
|
||||
|
||||
// Parameters:
|
||||
|
||||
// * frequency - Play the specified frequency indefinitely, turn off with toneAC().
|
||||
|
||||
// * volume - [optional] Set a volume level. (default: 10, range: 0 to 10 [0 = off])
|
||||
|
||||
// * length - [optional] Set the length to play in milliseconds. (default: 0 [forever], range: 0 to 2^32-1)
|
||||
|
||||
// * background - [optional] Play note in background or pause till finished? (default: false, values: true/false)
|
||||
|
||||
// toneAC() - Stop playing.
|
||||
|
||||
// noToneAC() - Same as toneAC().
|
||||
|
||||
//
|
||||
|
||||
// HISTORY:
|
||||
|
||||
// 01/27/2013 v1.2 - Fixed a counter error which went "over the top" and caused
|
||||
|
||||
// periods of silence (thanks Krodal). For advanced users needing tight code,
|
||||
|
||||
// the TONEAC_TINY switch in toneAC.h activates a version of toneAC() that
|
||||
|
||||
// saves 110 bytes. With TONEAC_TINY, the syntax is toneAC(frequency, length)
|
||||
|
||||
// while playing the note at full volume forever in the background. Added
|
||||
|
||||
// support for the ATmega 640, 644, 1281, 1284P and 2561 microcontrollers.
|
||||
|
||||
//
|
||||
|
||||
// 01/16/2013 v1.1 - Option to play notes in background, returning control back
|
||||
|
||||
// to your sketch for processing while note plays (similar to the way the tone
|
||||
|
||||
// library works). Volume is now linear and in the range from 0-10. Now uses
|
||||
|
||||
// prescaler 256 instead of 64 for frequencies below 122 Hz so it can go down
|
||||
|
||||
// to 1 Hz no matter what speed the CPU is clocked at (helpful if using toneAC
|
||||
|
||||
// to control a two-pin dual LED).
|
||||
|
||||
//
|
||||
|
||||
// 01/11/2013 v1.0 - Initial release.
|
||||
|
||||
//
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
#ifndef toneAC_h
|
||||
|
||||
#define toneAC_h
|
||||
|
||||
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <WProgram.h>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//#define TONEAC_TINY // Uncomment to use alternate function toneAC(frequency, length) that saves 110 bytes.
|
||||
|
||||
|
||||
|
||||
#if defined (__AVR_ATmega32U4__) || defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
|
||||
|
||||
#define PWMT1AMASK DDB5
|
||||
|
||||
#define PWMT1BMASK DDB6
|
||||
|
||||
#define PWMT1DREG DDRB
|
||||
|
||||
#define PWMT1PORT PORTB
|
||||
|
||||
#elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__)
|
||||
|
||||
#define PWMT1AMASK DDD4
|
||||
|
||||
#define PWMT1BMASK DDD5
|
||||
|
||||
#define PWMT1DREG DDRD
|
||||
|
||||
#define PWMT1PORT PORTD
|
||||
|
||||
#else
|
||||
|
||||
#define PWMT1AMASK DDB1
|
||||
|
||||
#define PWMT1BMASK DDB2
|
||||
|
||||
#define PWMT1DREG DDRB
|
||||
|
||||
#define PWMT1PORT PORTB
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__)
|
||||
|
||||
#define TIMSK1 TIMSK
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifndef TONEAC_TINY
|
||||
|
||||
void toneAC(unsigned long frequency = 0, uint8_t volume = 10, unsigned long length = 0, uint8_t background = false);
|
||||
|
||||
#else
|
||||
|
||||
void toneAC(unsigned long frequency = 0, unsigned long length = 0);
|
||||
|
||||
#endif
|
||||
|
||||
void noToneAC();
|
||||
|
||||
#endif
|
||||
35
Projects/ProgLab/toneAC.h/toneAC.h.ino
Normal file
35
Projects/ProgLab/toneAC.h/toneAC.h.ino
Normal file
@@ -0,0 +1,35 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// Connect your piezo buzzer (without internal oscillator) or speaker to these pins:
|
||||
// Pins 9 & 10 - ATmega328, ATmega128, ATmega640, ATmega8, Uno, Leonardo, etc.
|
||||
// Pins 11 & 12 - ATmega2560/2561, ATmega1280/1281, Mega
|
||||
// Pins 12 & 13 - ATmega1284P, ATmega644
|
||||
// Pins 14 & 15 - Teensy 2.0
|
||||
// Pins 25 & 26 - Teensy++ 2.0
|
||||
// Be sure to include an inline 100 ohm resistor on one pin as you normally do when connecting a piezo or speaker.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include "toneAC.h"
|
||||
|
||||
// Melody liberated from the toneMelody Arduino example sketch by Tom Igoe.
|
||||
int melody[] = { 262, 196, 196, 220, 196, 0, 247, 262 };
|
||||
int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 };
|
||||
|
||||
void setup() {} // Nothing to setup, just start playing!
|
||||
|
||||
void loop() {
|
||||
for (unsigned long freq = 125; freq <= 15000; freq += 10) {
|
||||
toneAC(freq); // Play the frequency (125 Hz to 15 kHz sweep in 10 Hz steps).
|
||||
delay(1); // Wait 1 ms so you can hear it.
|
||||
}
|
||||
toneAC(); // Turn off toneAC, can also use noToneAC().
|
||||
|
||||
delay(1000); // Wait a second.
|
||||
|
||||
for (int thisNote = 0; thisNote < 8; thisNote++) {
|
||||
int noteDuration = 1000/noteDurations[thisNote];
|
||||
toneAC(melody[thisNote], 10, noteDuration, true); // Play thisNote at full volume for noteDuration in the background.
|
||||
delay(noteDuration * 4 / 3); // Wait while the tone plays in the background, plus another 33% delay between notes.
|
||||
}
|
||||
|
||||
while(1); // Stop (so it doesn't repeat forever driving you crazy--you're welcome).
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
#include <Servo.h>
|
||||
|
||||
int relayPins[] = {4, 7, 6, 5};
|
||||
int buttonPins[] = {8, 9, 10, 11, 12, 13};
|
||||
int relayState[] = {0, 0, 0, 0};
|
||||
int buttonState = 0;
|
||||
|
||||
Servo myservo;
|
||||
|
||||
void setup() {
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (i < 4)
|
||||
{
|
||||
pinMode(relayPins[i], OUTPUT);
|
||||
}
|
||||
pinMode(buttonPins[i], INPUT_PULLUP);
|
||||
}
|
||||
|
||||
myservo.attach(3);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
buttonState = digitalRead(buttonPins[i]);
|
||||
if (buttonState == LOW)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 4:
|
||||
//
|
||||
break;
|
||||
case 3:
|
||||
// Turn on the servo for speaker
|
||||
myservo.write(150);
|
||||
delay(1000);
|
||||
myservo.write(140);
|
||||
break;
|
||||
default:
|
||||
relayChange(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (buttonState == LOW)
|
||||
{
|
||||
delay(50);
|
||||
buttonState = digitalRead(buttonPins[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void relayChange(int i)
|
||||
{
|
||||
if (relayState[i] == 0)
|
||||
{
|
||||
digitalWrite(relayPins[i], HIGH);
|
||||
relayState[i] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(relayPins[i], LOW);
|
||||
relayState[i] = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
|
||||
byte mac[] = {
|
||||
0x90, 0xA2, 0xDA, 0x0D, 0xA7, 0x51 };
|
||||
|
||||
IPAddress ip(10,0,0,5);
|
||||
|
||||
EthernetServer server(80);
|
||||
|
||||
int relayPins[] = {4, 7, 6, 5};
|
||||
int buttonPins[] = {8, 9, 10, 11, 12, 13};
|
||||
int relayState[] = {0, 0, 0, 0};
|
||||
int buttonState = 0;
|
||||
|
||||
String readString = String(100); //string for fetching data from address
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (i < 4)
|
||||
pinMode(relayPins[i], OUTPUT);
|
||||
pinMode(buttonPins[i], INPUT_PULLUP);
|
||||
}
|
||||
|
||||
// start the Ethernet connection and the server:
|
||||
|
||||
Serial.println(F("Initiaizing ethernet..."));
|
||||
|
||||
// this uses a fixed address
|
||||
Ethernet.begin(mac, ip);
|
||||
|
||||
// get an address with DHCP
|
||||
//if (Ethernet.begin(mac) == 0)
|
||||
// Serial.println("Failed to configure Ethernet using DHCP");
|
||||
|
||||
// give the card a second to initialize
|
||||
delay(1000);
|
||||
|
||||
server.begin();
|
||||
|
||||
Serial.print(F("Garage Door Opener Control Ready at IP address "));
|
||||
Serial.println(Ethernet.localIP());
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// command received (one character) '1' - activate garage door button
|
||||
char cmd = 0; // 1 - pulse button
|
||||
boolean done = false; // set to indicate that response is complete
|
||||
|
||||
// listen for incoming clients
|
||||
EthernetClient client = server.available();
|
||||
if (client)
|
||||
{
|
||||
Serial.println(F("new client"));
|
||||
readString = "";
|
||||
|
||||
while (client.connected())
|
||||
{
|
||||
if (client.available())
|
||||
{
|
||||
char c = client.read();
|
||||
Serial.write(c);
|
||||
|
||||
// store character received in receive string
|
||||
if (readString.length() < 100)
|
||||
readString += (c);
|
||||
|
||||
// check for end of line
|
||||
if (c == '\n')
|
||||
{
|
||||
// process line if its the "GET" request
|
||||
// a request looks like "GET /?1" or "GET /?2"
|
||||
if (readString.indexOf("GET") != -1)
|
||||
{
|
||||
if (readString.indexOf("?1") != -1)
|
||||
cmd = '1';
|
||||
// check for other commands here. ie turn on light, etc.
|
||||
if (readString.indexOf("?2") != -1)
|
||||
cmd = '2';
|
||||
if (readString.indexOf("?3") != -1)
|
||||
cmd = '3';
|
||||
if (readString.indexOf("?4") != -1)
|
||||
cmd = '4';
|
||||
if (readString.indexOf("?5") != -1)
|
||||
cmd = '5';
|
||||
if (readString.indexOf("?6") != -1)
|
||||
cmd = '6';
|
||||
if (readString.indexOf("?7") != -1)
|
||||
cmd = '7';
|
||||
if (readString.indexOf("?8") != -1)
|
||||
cmd = '8';
|
||||
}
|
||||
// if a blank line was received (just cr lf, length of 2), then its the end of the request
|
||||
if (readString.length() == 2)
|
||||
{
|
||||
if (cmd == '1'){
|
||||
Serial.println(F("Activate Button"));
|
||||
digitalWrite(6, HIGH);
|
||||
}
|
||||
if (cmd == '2'){
|
||||
Serial.println(F("Activate Button"));
|
||||
digitalWrite(6, LOW);
|
||||
}
|
||||
if (cmd == '3'){
|
||||
Serial.println(F("Activate Button"));
|
||||
digitalWrite(5, HIGH);
|
||||
}
|
||||
if (cmd == '4'){
|
||||
Serial.println(F("Activate Button"));
|
||||
digitalWrite(5, LOW);
|
||||
}
|
||||
if (cmd == '5'){
|
||||
Serial.println(F("Activate Button"));
|
||||
digitalWrite(7, HIGH);
|
||||
}
|
||||
if (cmd == '6'){
|
||||
Serial.println(F("Activate Button"));
|
||||
digitalWrite(7, LOW);
|
||||
}
|
||||
if (cmd == '7'){
|
||||
Serial.println(F("Activate Button"));
|
||||
digitalWrite(4, HIGH);
|
||||
}
|
||||
if (cmd == '8'){
|
||||
Serial.println(F("Activate Button"));
|
||||
digitalWrite(4, LOW);
|
||||
}
|
||||
// add other commands here
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
buttonState = digitalRead(buttonPins[i]);
|
||||
if (buttonState == LOW)
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
case 4:
|
||||
//
|
||||
break;
|
||||
case 3:
|
||||
// Turn on the servo for speaker
|
||||
/*
|
||||
myservo.write(300);
|
||||
delay(500);
|
||||
myservo.write(110);
|
||||
break;
|
||||
*/
|
||||
default:
|
||||
relayChange(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
while (buttonState == LOW)
|
||||
{
|
||||
delay(50);
|
||||
buttonState = digitalRead(buttonPins[i]);
|
||||
}*/
|
||||
}
|
||||
|
||||
// send web page back to client
|
||||
Serial.println(F("sending web page"));
|
||||
SendWebPage(client);
|
||||
Serial.println(F("web page sent"));
|
||||
|
||||
cmd = 0;
|
||||
|
||||
// break out and disconnect. This will tell the browser the request is complete without having to specify content-length
|
||||
break;
|
||||
|
||||
} // end of request reached
|
||||
|
||||
// start line over
|
||||
readString = "";
|
||||
} // end of line reached
|
||||
} // end data is available from client
|
||||
} // end cient is connected
|
||||
// give the web browser time to receive the data
|
||||
Serial.println(F("delay before disconnect"));
|
||||
delay(100);
|
||||
// close the connection:
|
||||
client.stop();
|
||||
Serial.println(F("client disonnected"));
|
||||
} // end client has been created
|
||||
}
|
||||
|
||||
void relayChange(int i)
|
||||
{
|
||||
if (relayState[i] == 0)
|
||||
{
|
||||
digitalWrite(relayPins[i], HIGH);
|
||||
relayState[i] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(relayPins[i], LOW);
|
||||
relayState[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// send web page
|
||||
void SendWebPage(EthernetClient client)
|
||||
{
|
||||
client.println(F("HTTP/1.1 200 OK"));
|
||||
client.println(F("Content-Type: text/html"));
|
||||
// to specify the length, wooul have to construct the entire string and then get its length
|
||||
//client.println("Content-Length: 1234");
|
||||
client.println(F("Connnection: close"));
|
||||
client.println();
|
||||
client.println(F("<!DOCTYPE HTML>"));
|
||||
client.println(F("<html>"));
|
||||
client.println(F("<head>"));
|
||||
client.println(F("<title>Home Automation Control</title>"));
|
||||
client.println(F("<style type='text/css'>"));
|
||||
client.println(F(".label {font-size: 30px; text-align:center;}"));
|
||||
client.println(F("button {width: 160px; height: 70px; font-size: 30px; -webkit-appearance: none; background-color:#dfe3ee; }"));
|
||||
client.println(F("</style>"));
|
||||
client.println(F("<script type='text/javascript'>"));
|
||||
client.println(F("function OnButtonClicked(parm) { window.location.href=\"X?\" + parm; }"));
|
||||
client.println(F("</script>"));
|
||||
client.println(F("</head>"));
|
||||
client.println(F("<body style=\"background-color:#3b5998\">"));
|
||||
client.println(F("<div class=\"label\">"));
|
||||
client.println(F("Home Auotmation Control<br/><br/>"));
|
||||
|
||||
|
||||
// door open / close button
|
||||
if (digitalRead(6)==LOW)
|
||||
client.println(F("<button onclick=\"OnButtonClicked('1');\">1ON</button><br/><br/>"));
|
||||
if (digitalRead(6)==HIGH)
|
||||
client.println(F("<button onclick=\"OnButtonClicked('2');\">1Off</button><br/><br/>"));
|
||||
if (digitalRead(5)==LOW)
|
||||
client.println(F("<button onclick=\"OnButtonClicked('3');\">2ON</button><br/><br/>"));
|
||||
if (digitalRead(5)==HIGH)
|
||||
client.println(F("<button onclick=\"OnButtonClicked('4');\">2Off</button><br/><br/>"));
|
||||
if (digitalRead(7)==LOW)
|
||||
client.println(F("<button onclick=\"OnButtonClicked('5');\">3ON</button><br/><br/>"));
|
||||
if (digitalRead(7)==HIGH)
|
||||
client.println(F("<button onclick=\"OnButtonClicked('6');\">3Off</button><br/><br/>"));
|
||||
if (digitalRead(4)==LOW)
|
||||
client.println(F("<button onclick=\"OnButtonClicked('7');\">4ON</button><br/><br/>"));
|
||||
if (digitalRead(4)==HIGH)
|
||||
client.println(F("<button onclick=\"OnButtonClicked('8');\">4Off</button><br/><br/>"));
|
||||
|
||||
// add more buttons here
|
||||
// button separator
|
||||
|
||||
client.println(F("</div>"));
|
||||
|
||||
client.println(F("</body>"));
|
||||
client.println(F("</html>"));
|
||||
|
||||
client.println("");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <Servo.h>
|
||||
|
||||
byte mac[] = {
|
||||
0x90, 0xA2, 0xDA, 0x0D, 0xA7, 0x51};
|
||||
|
||||
IPAddress ip(10,0,0,5);
|
||||
EthernetServer server(81);
|
||||
|
||||
int relayPins[] = {7, 6, 5, 4};
|
||||
int buttonPins[] = {8, 9, 10, 11, 12, 13};
|
||||
int relayState[] = {0, 0, 0, 0};
|
||||
int buttonState = 0;
|
||||
|
||||
Servo speakerServo;
|
||||
|
||||
String readString = String(100);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
Serial.println("RUN");
|
||||
if (i < 4)
|
||||
pinMode(relayPins[i], OUTPUT);
|
||||
pinMode(buttonPins[i], INPUT_PULLUP);
|
||||
}
|
||||
|
||||
speakerServo.attach(3);
|
||||
|
||||
Serial.println(F("Initialaizing ethernet..."));
|
||||
Ethernet.begin(mac, ip);
|
||||
|
||||
delay(1000);
|
||||
|
||||
server.begin();
|
||||
Serial.print(F("Kevin's RelayController ready at: "));
|
||||
Serial.println(Ethernet.localIP());
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int cmd = 0;
|
||||
boolean done = false;
|
||||
|
||||
//checkButtons();
|
||||
|
||||
EthernetClient client = server.available();
|
||||
|
||||
if (client)
|
||||
{
|
||||
Serial.println(F("new client"));
|
||||
readString = "";
|
||||
|
||||
while (client.connected())
|
||||
{
|
||||
if (client.available())
|
||||
{
|
||||
char c = client.read();
|
||||
Serial.write(c);
|
||||
if (readString.length() < 100)
|
||||
readString += (c);
|
||||
|
||||
// Check serverInputs
|
||||
if (c == '\n')
|
||||
{
|
||||
if (readString.indexOf("GET") != -1)
|
||||
{
|
||||
if (readString.indexOf("?1") != -1)
|
||||
cmd = 1;
|
||||
if (readString.indexOf("?2") != -1)
|
||||
cmd = 2;
|
||||
if (readString.indexOf("?3") != -1)
|
||||
cmd = 3;
|
||||
if (readString.indexOf("?4") != -1)
|
||||
cmd = 4;
|
||||
if (readString.indexOf("?5") != -1)
|
||||
cmd = 5;
|
||||
if (readString.indexOf("?6") != -1)
|
||||
cmd = 6;
|
||||
if (readString.indexOf("?7") != -1)
|
||||
cmd = 7;
|
||||
if (readString.indexOf("?8") != -1)
|
||||
cmd = 8;
|
||||
if (readString.indexOf("?9") != -1)
|
||||
cmd = 9;
|
||||
if (readString.indexOf("?10") != -1)
|
||||
cmd = 10;
|
||||
}
|
||||
//Serial.println(cmd);
|
||||
if (readString.length() >= 2)
|
||||
{
|
||||
changeState(cmd);
|
||||
Serial.println(F("Sending web page"));
|
||||
SendWebPage(client);
|
||||
Serial.println(F("Web page sent!"));
|
||||
cmd = 0;
|
||||
break;
|
||||
}
|
||||
readString = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
Serial.println(F("Delay before disconnecting"));
|
||||
delay(50);
|
||||
client.stop();
|
||||
Serial.println(F("Client disconnected"));
|
||||
}
|
||||
}
|
||||
|
||||
void changeState(int n)
|
||||
{
|
||||
Serial.println(n);
|
||||
if (n > 0 && n <= 4)
|
||||
{
|
||||
Serial.println(F("Activate Button"));
|
||||
digitalWrite(relayPins[n - 1], HIGH);
|
||||
}
|
||||
else if (n > 4 && n <= 8)
|
||||
{
|
||||
Serial.println(F("Activate Button"));
|
||||
digitalWrite(relayPins[n - 5], LOW);
|
||||
}
|
||||
else if (n == 9)
|
||||
{
|
||||
Serial.println(F("Activate Button"));
|
||||
speakerServo.write(156);
|
||||
delay(500);
|
||||
speakerServo.write(140);
|
||||
}
|
||||
else if (n == 10)
|
||||
{
|
||||
Serial.println(F("Activate Button"));
|
||||
// Do something
|
||||
}
|
||||
}
|
||||
|
||||
void checkButtons()
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
buttonState = digitalRead(buttonPins[i]);
|
||||
if (buttonState == LOW)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 4:
|
||||
//
|
||||
break;
|
||||
case 3:
|
||||
// Turn on the servo for speaker
|
||||
speakerServo.write(156);
|
||||
delay(500);
|
||||
speakerServo.write(140);
|
||||
break;
|
||||
default:
|
||||
relayChange(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (buttonState == LOW)
|
||||
{
|
||||
delay(50);
|
||||
buttonState = digitalRead(buttonPins[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void relayChange(int i)
|
||||
{
|
||||
if (relayState[i] == 0)
|
||||
{
|
||||
digitalWrite(relayPins[i], HIGH);
|
||||
relayState[i] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(relayPins[i], LOW);
|
||||
relayState[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void SendWebPage(EthernetClient client)
|
||||
{
|
||||
client.println(F("HTTP/1.1 200 OK"));
|
||||
client.println(F("Content-Type: text/html"));
|
||||
client.println(F("Connection: close"));
|
||||
client.println();
|
||||
client.println(F("<!DOCTYPE HTML>"));
|
||||
client.println(F("<html>"));
|
||||
client.println(F("<head>"));
|
||||
client.println(F("<meta name=\"viewport\" content=\"width=370\">"));
|
||||
client.println(F("<link rel=\"apple-touch-icon\" href=\"http://i.imgur.com/zOjuLwC.png\"/>"));
|
||||
client.println(F("<link href='http://fonts.googleapis.com/css?family=Pontano+Sans' rel='stylesheet' type='text/css'>"));
|
||||
client.println(F("<title>RelayController</title>"));
|
||||
client.println(F("<style type='text/css'>"));
|
||||
client.println(F(".label {display:label; color: white; font-size: 30px; font-family: 'Pontano Sans', sans-serif; text-align:center;}"));
|
||||
client.println(F("button {position: relative; vertical-align: top; width: 140px; height: 60px; padding: 0; font-size: 22px; color: white; text-align: center; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); background: #e74c3c; border: 0; border-bottom: 2px solid #c0392b; cursor: pointer; -webkit-box-shadow: inset 0 -2px #c0392b; box-shadow: inset 0 -2px #c0392b;}"));
|
||||
client.println(F("</style>"));
|
||||
client.println(F("<script type ='text/javascript'>"));
|
||||
client.println(F("function OnButtonClicked(parm) { window.location.href=\"X?\" + parm; }"));
|
||||
client.println(F("</script>"));
|
||||
client.println(F("<body style=\"background-color:#1b354f\">"));
|
||||
client.println(F("<div class=\"label\">"));
|
||||
client.println(F("<br/>RelayController<br/><br/>"));
|
||||
|
||||
// Buttons
|
||||
if (digitalRead(relayPins[0]) == LOW)
|
||||
client.println(F("<button onclick=\"OnButtonClicked('1');\">1ON</button>"));
|
||||
else
|
||||
client.println(F("<button onclick=\"OnButtonClicked('5');\">1OFF</button>"));
|
||||
if (digitalRead(relayPins[1]) == LOW)
|
||||
client.println(F("<button onclick=\"OnButtonClicked('2');\">2ON</button><br/><br/>"));
|
||||
else
|
||||
client.println(F("<button onclick=\"OnButtonClicked('6');\">2OFF</button><br/><br/>"));
|
||||
if (digitalRead(relayPins[2]) == LOW)
|
||||
client.println(F("<button onclick=\"OnButtonClicked('3');\">3ON</button>"));
|
||||
else
|
||||
client.println(F("<button onclick=\"OnButtonClicked('7');\">3OFF</button>"));
|
||||
if (digitalRead(relayPins[3]) == LOW)
|
||||
client.println(F("<button onclick=\"OnButtonClicked('4');\">4ON</button><br/><br/>"));
|
||||
else
|
||||
client.println(F("<button onclick=\"OnButtonClicked('8');\">4OFF</button><br/><br/>"));
|
||||
|
||||
client.println(F("<button onclick=\"OnButtonClicked('9');\">5</button>"));
|
||||
client.println(F("<button onclick=\"OnButtonClicked('10');\">6</button><br/><br/>"));
|
||||
|
||||
client.println(F("</div>"));
|
||||
client.println(F("</body>"));
|
||||
client.println(F("</html>"));
|
||||
client.println("");
|
||||
}
|
||||
|
||||
31
Projects/Reset/Reset.ino
Executable file
31
Projects/Reset/Reset.ino
Executable file
@@ -0,0 +1,31 @@
|
||||
int led = 13;//pin 13 as OUTPUT LED pin
|
||||
int resetPin = 3;
|
||||
// the setup routine runs once when you press reset:
|
||||
void setup() {
|
||||
digitalWrite(resetPin, LOW);
|
||||
delay(200);
|
||||
// initialize the digital pin as an output.
|
||||
pinMode(led, OUTPUT);
|
||||
pinMode(resetPin, OUTPUT);
|
||||
Serial.begin(9600);//initialize Serial Port
|
||||
Serial.println("reset");//print reset to know the program has been reset and
|
||||
//the setup function happened
|
||||
delay(200);
|
||||
}
|
||||
|
||||
// the loop routine runs over and over again forever:
|
||||
void loop() {
|
||||
delay(10);
|
||||
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
|
||||
Serial.println("on");
|
||||
delay(1000); // wait for a second
|
||||
digitalWrite(led, HIGH); // turn the LED off by making the voltage LOW
|
||||
Serial.println("off");
|
||||
delay(1000); // wait for a second
|
||||
Serial.println("resetting");
|
||||
delay(10);
|
||||
digitalWrite(resetPin, HIGH);
|
||||
Serial.println("this never happens");
|
||||
//this never happens because Arduino resets
|
||||
|
||||
}
|
||||
222
Projects/ST_Two_Small_Clock/ST2_Main/ST2_Main.ino
Normal file
222
Projects/ST_Two_Small_Clock/ST2_Main/ST2_Main.ino
Normal file
@@ -0,0 +1,222 @@
|
||||
//*******************************************************************************************************************
|
||||
// Main Loop
|
||||
//*******************************************************************************************************************
|
||||
void loop()
|
||||
{
|
||||
// Test for Sleep ------------------------------------------------*
|
||||
|
||||
currentMillis = millis();
|
||||
OptionModeFlag = false;
|
||||
|
||||
if(((currentMillis - SleepTimer) > SleepLimit) && SleepEnable)
|
||||
{
|
||||
|
||||
if(STATE= 1) // New for ST Desk Clock - goto Time vs Sleep
|
||||
{
|
||||
SUBSTATE = 1;
|
||||
blinkON = true;
|
||||
blinkFlag = false;
|
||||
blinkMin = false;
|
||||
blinkHour = false;
|
||||
}else
|
||||
{
|
||||
STATE= 1; // was STATE= 99;
|
||||
SUBSTATE = 0;
|
||||
}
|
||||
|
||||
SleepTimer = millis();
|
||||
|
||||
}
|
||||
|
||||
// Test for Mode Button Press ------------------------------------*
|
||||
|
||||
bval = !digitalRead(MODEBUTTON);
|
||||
if(bval)
|
||||
{
|
||||
if(ALARMON)
|
||||
{
|
||||
CheckAlarm();
|
||||
}
|
||||
|
||||
if(ALARM1FLAG)
|
||||
{
|
||||
ALARM1FLAG = false;
|
||||
ALARMON = false;
|
||||
EnableAlarm1(false);
|
||||
STATE = 90;
|
||||
JustWokeUpFlag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(JustWokeUpFlag)
|
||||
{
|
||||
JustWokeUpFlag = false;
|
||||
JustWokeUpFlag2 = true; // Used to supress "Time" text from showing when waking up.
|
||||
}
|
||||
else
|
||||
{
|
||||
NextStateRequest = true;
|
||||
}
|
||||
// SUBSTATE = 99;
|
||||
|
||||
while(bval)
|
||||
{
|
||||
bval = !digitalRead(SETBUTTON);
|
||||
if(bval)
|
||||
{
|
||||
OptionModeFlag = true;
|
||||
NextStateRequest = false;
|
||||
NextSUBStateRequest = false;
|
||||
displayString("SPEC");
|
||||
delay(300);
|
||||
}
|
||||
bval = !digitalRead(MODEBUTTON);
|
||||
}
|
||||
|
||||
delay(100);
|
||||
SleepTimer = millis();
|
||||
}
|
||||
}
|
||||
|
||||
// Test for SET Button Press ------------------------------------*
|
||||
|
||||
bval = !digitalRead(SETBUTTON);
|
||||
if(bval && !OptionModeFlag)
|
||||
{
|
||||
NextSUBStateRequest = true;
|
||||
|
||||
while(bval)
|
||||
{
|
||||
|
||||
bval = !digitalRead(MODEBUTTON);
|
||||
if(bval)
|
||||
{
|
||||
OptionModeFlag = true;
|
||||
NextStateRequest = false;
|
||||
NextSUBStateRequest = false;
|
||||
displayString("SPEC");
|
||||
delay(300);
|
||||
}
|
||||
|
||||
|
||||
bval = !digitalRead(SETBUTTON);
|
||||
}
|
||||
delay(100);
|
||||
SleepTimer = millis();
|
||||
}
|
||||
|
||||
// Running Blink counter ------------------------------------*
|
||||
if(blinkFlag)
|
||||
{
|
||||
blinkCounter = blinkCounter +1;
|
||||
if(blinkCounter >blinkTime) // was 150
|
||||
{
|
||||
blinkON = !blinkON;
|
||||
blinkCounter = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
blinkON = true; // Not blinking, just leave the LEDs lit
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// Main Loop - State Machine
|
||||
//*******************************************************************************************************************
|
||||
|
||||
switch (STATE)
|
||||
{
|
||||
case 0: // Set-Up
|
||||
STATE = 1;
|
||||
break;
|
||||
|
||||
case 1: // Display Time
|
||||
DisplayTimeSub();
|
||||
break;
|
||||
|
||||
case 2: // Set Time
|
||||
setAlarmSub();
|
||||
break;
|
||||
|
||||
case 3: // Config Alarm
|
||||
setTimeSub();
|
||||
break;
|
||||
|
||||
case 4: // Stop Watch
|
||||
StopWatch();
|
||||
break;
|
||||
|
||||
|
||||
case 5: // Serial Display
|
||||
DisplaySerialData();
|
||||
break;
|
||||
|
||||
case 6: // Graphic Demo
|
||||
graphican();
|
||||
break;
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
case 90: // Alarm Triggered
|
||||
|
||||
blinkFlag = true;
|
||||
displayString("Beep");
|
||||
|
||||
if(blinkON)
|
||||
{
|
||||
pinMode(SETBUTTON, OUTPUT);
|
||||
tone(SETBUTTON,4000) ;
|
||||
delay(100);
|
||||
noTone(SETBUTTON);
|
||||
digitalWrite(SETBUTTON, HIGH);
|
||||
}
|
||||
|
||||
#if ARDUINO >= 101
|
||||
pinMode(SETBUTTON, INPUT_PULLUP);
|
||||
// digitalWrite(SETBUTTON, HIGH);
|
||||
#else
|
||||
// digitalWrite(SETBUTTON, HIGH);
|
||||
pinMode(SETBUTTON, INPUT);
|
||||
#endif
|
||||
delay(250);
|
||||
|
||||
// bval = !digitalRead(SETBUTTON);
|
||||
if(NextSUBStateRequest | NextStateRequest)
|
||||
{
|
||||
STATE = 0;
|
||||
SUBSTATE = 0;
|
||||
// NextStateFlag = true;
|
||||
NextStateRequest = false;
|
||||
NextSUBStateRequest = false;
|
||||
blinkFlag = false;
|
||||
}
|
||||
break;
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
case 99: // Sleep
|
||||
displayString("Nite");
|
||||
delay(500);
|
||||
clearmatrix();
|
||||
GoToSleep();
|
||||
SleepTimer = millis();
|
||||
STATE = 0;
|
||||
SUBSTATE = 0;
|
||||
break;
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// End of Main Loop
|
||||
//*******************************************************************************************************************
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
170
Projects/ST_Two_Small_Clock/ST2_Matrix/ST2_Matrix.ino
Normal file
170
Projects/ST_Two_Small_Clock/ST2_Matrix/ST2_Matrix.ino
Normal file
@@ -0,0 +1,170 @@
|
||||
//*******************************************************************************************************************
|
||||
// Called by Timer 1 Interrupt to draw next column in LED matrix
|
||||
//*******************************************************************************************************************
|
||||
// Only light one ROW (and one column) ie one pixel at a time. = lower current draw, but lower refresh rate.
|
||||
|
||||
|
||||
void LEDupdateTWO() // ONE ROW of selected column at a time
|
||||
{
|
||||
|
||||
if(ROWBITINDEX >6)
|
||||
{
|
||||
Mcolumn = Mcolumn+1; // Prep for next column
|
||||
if(Mcolumn >19)
|
||||
{
|
||||
Mcolumn =0;
|
||||
}
|
||||
|
||||
PORTB = (PORTB & B10000000); // Clear last column
|
||||
PORTC = (PORTC & B11110000) | B00001111;
|
||||
|
||||
if(Mcolumn <16) // Matrix column (from 0 to 19)
|
||||
{
|
||||
PORTB = (PORTB & B01111111); //| (0<<PORTB7); // Decode digit Col. 1 to 16 - Select De-Mux chip
|
||||
|
||||
PORTD = (PORTD & B00001111) | (Mcolumn << 4); // Decode address to 74HC154
|
||||
}
|
||||
else
|
||||
{
|
||||
PORTB = (1<<PORTB7); // Decode digit Col. 17 to 20 - UN-Select De-Mux chip
|
||||
|
||||
PORTC = (PORTC & B11110000) | ~(1<<(Mcolumn-16)); // Using PC0 to PC4 to address col. 17 to 20 directly
|
||||
}
|
||||
|
||||
ROWBITINDEX = 0;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
PORTB = (PORTB & B10000000);
|
||||
if(bitRead(LEDMAT[Mcolumn],ROWBITINDEX))
|
||||
{
|
||||
// PORTB = (PORTB & B10000000);
|
||||
bitSet(PORTB,ROWBITINDEX);
|
||||
}
|
||||
|
||||
if(Mcolumn <16) // Matrix column (from 0 to 19)
|
||||
{
|
||||
delayMicroseconds(120);
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// bitClear(PORTB,ROWBITINDEX);
|
||||
// }
|
||||
|
||||
ROWBITINDEX = ROWBITINDEX +1;
|
||||
}
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// Called by Timer 1 Interrupt to draw next column in LED matrix
|
||||
//*******************************************************************************************************************
|
||||
// This version of LED refresh / drawing lights full column at once = higher current draw (but can be brighter)
|
||||
|
||||
void LEDupdate() // All ROWs of selected column at the same time
|
||||
{
|
||||
|
||||
PORTB = (PORTB & B10000000); // Clear last column
|
||||
PORTC = (PORTC & B11110000) | B00001111;
|
||||
|
||||
if(Mcolumn <16) // Matrix column (from 0 to 19)
|
||||
{
|
||||
PORTB = (PORTB & B01111111); //| (0<<PORTB7); // Decode digit Col. 1 to 16 - Select De-Mux chip
|
||||
|
||||
PORTD = (PORTD & B00001111) | (Mcolumn << 4); // Decode address to 74HC154
|
||||
}
|
||||
else
|
||||
{
|
||||
PORTB = (1<<PORTB7); // Decode digit Col. 17 to 20 - UN-Select De-Mux chip
|
||||
|
||||
PORTC = (PORTC & B11110000) | ~(1<<(Mcolumn-16)); // Using PC0 to PC4 to address col. 17 to 20 directly
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
PORTB = (PORTB & B10000000) | (LEDMAT[Mcolumn]); // Light LEDs - turn on ROWs
|
||||
|
||||
// ---
|
||||
|
||||
Mcolumn = Mcolumn+1; // Prep for next column
|
||||
if(Mcolumn >19)
|
||||
{
|
||||
Mcolumn =0;
|
||||
}
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// Used by STII Small Desk Clock
|
||||
//*******************************************************************************************************************
|
||||
// Only light one ROW (and one column) ie one pixel at a time. = lower current draw, but lower refresh rate.
|
||||
|
||||
|
||||
// Where:
|
||||
// PORTC2 - S1 (ADC1)
|
||||
// PORTC3 - S2 (ADC2)
|
||||
// When S1=H and S2=L Decoder 1 = Selected
|
||||
// When S1=L and S2=H Decoder 2 = Selected
|
||||
// When S1=L and S2=L Decoder 3 = Selected
|
||||
// When S1=H and S2=H None Selected = all columns are OFF
|
||||
|
||||
// PORTD4 - A
|
||||
// PORTD5 - B
|
||||
// PORTD6 - C
|
||||
// PORTD7 - Free pin (only with the "Small desk clock")
|
||||
|
||||
// PORTB 0 to 6 = ROWS 1 to 7
|
||||
|
||||
void LEDupdateTHREE() // ONE ROW of selected column at a time
|
||||
{
|
||||
|
||||
if(ROWBITINDEX >6)
|
||||
{
|
||||
ROWBITINDEX = 0;
|
||||
|
||||
Mcolumn = Mcolumn+1; // Prep for next column
|
||||
if(Mcolumn >19)
|
||||
{
|
||||
Mcolumn =0;
|
||||
}
|
||||
|
||||
// PORTB = (PORTB & B10000000); // Clear last column
|
||||
PORTB = (PORTB & B10000000);
|
||||
PORTC = (PORTC & B11110011) | B00001100; // Turn off decoders
|
||||
|
||||
|
||||
|
||||
if(Mcolumn < 8) // Matrix column (from 0 to 7)
|
||||
{
|
||||
PORTD = (PORTD & B10001111) | (Mcolumn << 4); // Decode address to 74HC138
|
||||
PORTC = (PORTC & B11110011) | B00000100; // Select Chip 1
|
||||
}
|
||||
|
||||
if(Mcolumn > 7 && Mcolumn < 16)
|
||||
{
|
||||
PORTD = (PORTD & B10001111) | ((Mcolumn - 8) << 4); // Decode address to 74HC138
|
||||
PORTC = (PORTC & B11110011) | B00001000; // Select Chip 2
|
||||
}
|
||||
|
||||
if(Mcolumn > 15)
|
||||
{
|
||||
PORTD = (PORTD & B10001111) | ((Mcolumn - 16) << 4); // Decode address to 74HC138
|
||||
PORTC = (PORTC & B11110011); // Select Chip 3
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// PORTB = (PORTB & B10000000);
|
||||
PORTB = (PORTB & B10000000);
|
||||
if(bitRead(LEDMAT[Mcolumn],ROWBITINDEX))
|
||||
{
|
||||
// PORTB = (PORTB & B10000000);
|
||||
bitSet(PORTB,ROWBITINDEX);
|
||||
}
|
||||
|
||||
ROWBITINDEX = ROWBITINDEX +1;
|
||||
|
||||
delayMicroseconds(50); // Test to see if this makes LEDs brighter
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
526
Projects/ST_Two_Small_Clock/ST2_RTC/ST2_RTC.ino
Normal file
526
Projects/ST_Two_Small_Clock/ST2_RTC/ST2_RTC.ino
Normal file
@@ -0,0 +1,526 @@
|
||||
//*******************************************************************************************************************
|
||||
// Check Time
|
||||
//*******************************************************************************************************************
|
||||
void checktime()
|
||||
{
|
||||
uint8_t temp =0;
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_SEC);
|
||||
SecOnes = i2cData & B00001111; //
|
||||
|
||||
SecTens = i2cData & B01110000; //
|
||||
SecTens = SecTens >> 4;
|
||||
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_MIN);
|
||||
MinOnes = i2cData & B00001111; //
|
||||
|
||||
MinTens = i2cData & B01110000; //
|
||||
MinTens = MinTens >> 4;
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_HOUR);
|
||||
HourOnes = i2cData & B00001111; //
|
||||
|
||||
TH_Not24_flag = bitRead(i2cData, 6); // False on RTC when 24 mode selected
|
||||
PM_NotAM_flag = bitRead(i2cData, 5);
|
||||
|
||||
if(TH_Not24_flag == true)
|
||||
{
|
||||
HourTens = i2cData & B00010000; //
|
||||
HourTens = HourTens >> 4;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
HourTens = i2cData & B00110000; //
|
||||
HourTens = HourTens >> 4;
|
||||
}
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// Check Date
|
||||
//*******************************************************************************************************************
|
||||
void checkDate()
|
||||
{
|
||||
|
||||
int temp = 0;
|
||||
I2C_RX(RTCDS1337,RTC_DAY);
|
||||
Days = i2cData & B00000111; //
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_MONTH);
|
||||
MonthCode = i2cData & B00001111; //
|
||||
|
||||
temp = (i2cData & B00010000) >> 4;
|
||||
if(temp)
|
||||
{
|
||||
MonthCode = MonthCode +10; // Convert BCD month into interger month
|
||||
}
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_DATE);
|
||||
DateOnes = i2cData & B00001111; //
|
||||
DateTens = (i2cData & B00110000) >> 4;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// SET Time - NEW
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void settimeNEW(uint8_t setselect) // both min digits or both hour digits (advance one at a time)
|
||||
{
|
||||
uint8_t temp =0;
|
||||
switch(setselect)
|
||||
{
|
||||
|
||||
case 1:
|
||||
MinOnes = MinOnes +1;
|
||||
if(MinOnes >9)
|
||||
{
|
||||
MinOnes = 0;
|
||||
|
||||
MinTens = MinTens +1;
|
||||
if(MinTens >5)
|
||||
{
|
||||
MinTens = 0;
|
||||
}
|
||||
|
||||
// temp = (MinTens << 4) + MinOnes;
|
||||
// I2C_TX(RTCDS1337,RTC_MIN,temp);
|
||||
}
|
||||
|
||||
temp = (MinTens << 4) + MinOnes;
|
||||
I2C_TX(RTCDS1337,RTC_MIN,temp);
|
||||
break;
|
||||
|
||||
|
||||
// -----------------------------------------------
|
||||
|
||||
case 2:
|
||||
HourOnes = HourOnes +1;
|
||||
|
||||
if(TH_Not24_flag)
|
||||
// 12 hours mode increment
|
||||
{
|
||||
|
||||
if(HourOnes >9 )
|
||||
{
|
||||
HourOnes = 0;
|
||||
HourTens = 1;
|
||||
}
|
||||
|
||||
if((HourOnes ==2) && (HourTens == 1))
|
||||
{
|
||||
PM_NotAM_flag = !PM_NotAM_flag;
|
||||
}
|
||||
|
||||
if((HourOnes >2) && (HourTens == 1))
|
||||
{
|
||||
// PM_NotAM_flag = !PM_NotAM_flag;
|
||||
HourTens = 0;
|
||||
HourOnes = 1;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
// 24 hours mode increment - S
|
||||
{
|
||||
|
||||
if((HourOnes >9) && (HourTens < 2))
|
||||
{
|
||||
HourOnes = 0;
|
||||
HourTens = HourTens +1;
|
||||
}
|
||||
|
||||
if((HourTens ==2) && (HourOnes == 4))
|
||||
{
|
||||
HourOnes = 0;
|
||||
HourTens = 0;
|
||||
}
|
||||
}
|
||||
// 24 hours mode increment - E
|
||||
|
||||
temp = (HourTens << 4) + HourOnes;
|
||||
if(TH_Not24_flag)
|
||||
{
|
||||
bitWrite(temp, 5, PM_NotAM_flag);
|
||||
}
|
||||
|
||||
bitWrite(temp, 6, TH_Not24_flag);
|
||||
I2C_TX(RTCDS1337,RTC_HOUR,temp);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
Days = Days +1 ;
|
||||
if(Days>7)
|
||||
{
|
||||
Days = 1;
|
||||
}
|
||||
temp = Days & B00000111; //
|
||||
I2C_TX(RTCDS1337,RTC_DAY,temp);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
temp = 0;
|
||||
MonthCode = MonthCode +1 ;
|
||||
if(MonthCode >12)
|
||||
{
|
||||
MonthCode = 1;
|
||||
}
|
||||
if(MonthCode>9)
|
||||
{
|
||||
temp = MonthCode - 10;
|
||||
// MonthCode = MonthCode & B00001111;
|
||||
bitSet(temp, 4); // Convert int to BCD
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = MonthCode & B00001111;
|
||||
}
|
||||
|
||||
I2C_TX(RTCDS1337,RTC_MONTH,temp);
|
||||
break;
|
||||
|
||||
case 5: // Date
|
||||
|
||||
// I2C_RX(RTCDS1337,RTC_DATE);
|
||||
// DateOnes = i2cData & B00001111;
|
||||
// DateTens = (i2cData & B00110000) >> 4;
|
||||
DateOnes = DateOnes + 1;
|
||||
if((DateTens == 3) && (DateOnes > 1))
|
||||
{
|
||||
DateOnes = 1;
|
||||
DateTens =0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(DateOnes>9)
|
||||
{
|
||||
DateOnes = 0;
|
||||
DateTens = DateTens +1;
|
||||
}
|
||||
}
|
||||
temp = (DateOnes & B00001111) | ((DateTens << 4) & B00110000);
|
||||
I2C_TX(RTCDS1337,RTC_DATE,temp);
|
||||
break;
|
||||
|
||||
case 6: // year
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// 12:00 Start Time
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void SetStartTime()
|
||||
{
|
||||
uint8_t temp =0;
|
||||
|
||||
HourTens = 1;
|
||||
HourOnes = 2;
|
||||
temp = (HourTens << 4) + HourOnes;
|
||||
bitWrite(temp, 5, PM_NotAM_flag);
|
||||
bitWrite(temp, 6, TH_Not24_flag);
|
||||
|
||||
I2C_TX(RTCDS1337,RTC_HOUR,temp);
|
||||
|
||||
MinTens = 0;
|
||||
MinOnes = 0;
|
||||
temp = (MinTens << 4) + MinOnes;
|
||||
I2C_TX(RTCDS1337,RTC_MIN,temp);
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// SET Alarm
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void SetAlarmTime() // Just for testing set to 12:01 PM
|
||||
{
|
||||
uint8_t temp =0;
|
||||
|
||||
HourTens = 1;
|
||||
HourOnes = 2;
|
||||
temp = (HourTens << 4) + HourOnes;
|
||||
bitWrite(temp, 5, A_PM_NotAM_flag);
|
||||
bitWrite(temp, 6, A_TH_Not24_flag);
|
||||
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1HOUR,temp);
|
||||
|
||||
MinTens = 0;
|
||||
MinOnes = 1;
|
||||
temp = (MinTens << 4) + MinOnes;
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1MIN,temp);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// Check Alarm
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void CheckAlarm()
|
||||
{
|
||||
uint8_t temp =0;
|
||||
I2C_RX(RTCDS1337,RTCSTATUS);
|
||||
ALARM1FLAG = bitRead(i2cData, 0);
|
||||
|
||||
if(ALARM1FLAG)
|
||||
{
|
||||
temp =i2cData;
|
||||
bitClear(temp, 0);
|
||||
I2C_TX(RTCDS1337,RTCSTATUS,temp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// Enable Alarm
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void EnableAlarm1(boolean onoff) // Trigger on Hours & Minutes Match
|
||||
{
|
||||
uint8_t temp =0;
|
||||
|
||||
// Adjust for Hours - Minutes Trigger -S
|
||||
I2C_RX(RTCDS1337,RTC_ALARM1SEC);
|
||||
temp =i2cData;
|
||||
bitClear(temp, 7);
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1SEC,temp);
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_ALARM1MIN);
|
||||
temp =i2cData;
|
||||
bitClear(temp, 7);
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1MIN,temp);
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_ALARM1HOUR);
|
||||
temp =i2cData;
|
||||
bitClear(temp, 7);
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1HOUR,temp);
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_ALARM1DATE);
|
||||
temp =i2cData;
|
||||
bitSet(temp, 7);
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1DATE,temp);
|
||||
// Adjust for Hours - Minutes Trigger -E
|
||||
|
||||
I2C_RX(RTCDS1337,RTCCONT); // Enable Alarm Pin on RTC
|
||||
temp =i2cData;
|
||||
|
||||
if(onoff)
|
||||
{
|
||||
bitSet(temp, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
bitClear(temp, 0);
|
||||
}
|
||||
I2C_TX(RTCDS1337,RTCCONT,temp);
|
||||
|
||||
I2C_RX(RTCDS1337,RTCSTATUS); // Clear Alarm RTC internal Alarm Flag
|
||||
temp =i2cData;
|
||||
bitClear(temp, 0);
|
||||
I2C_TX(RTCDS1337,RTCSTATUS,temp);
|
||||
}
|
||||
//*******************************************************************************************************************
|
||||
// SET ALARM TIME
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void setAlarm(uint8_t setselect) // both min digits or both hour digits (advance one at a time)
|
||||
{
|
||||
uint8_t temp =0;
|
||||
switch(setselect)
|
||||
{
|
||||
|
||||
case 1:
|
||||
AMinOnes = AMinOnes +1;
|
||||
if(AMinOnes >9)
|
||||
{
|
||||
AMinOnes = 0;
|
||||
|
||||
AMinTens = AMinTens +1;
|
||||
if(AMinTens >5)
|
||||
{
|
||||
AMinTens = 0;
|
||||
}
|
||||
}
|
||||
|
||||
temp = (AMinTens << 4) + AMinOnes;
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1MIN,temp);
|
||||
break;
|
||||
|
||||
|
||||
case 2:
|
||||
AHourOnes = AHourOnes +1;
|
||||
|
||||
// -----------*
|
||||
if(A_TH_Not24_flag)
|
||||
// 12 hours mode increment
|
||||
{
|
||||
|
||||
if(AHourOnes >9 )
|
||||
{
|
||||
AHourOnes = 0;
|
||||
AHourTens = 1;
|
||||
}
|
||||
|
||||
if((AHourOnes ==2) && (AHourTens == 1))
|
||||
{
|
||||
A_PM_NotAM_flag = !A_PM_NotAM_flag;
|
||||
}
|
||||
|
||||
if((AHourOnes >2) && (AHourTens == 1))
|
||||
{
|
||||
// PM_NotAM_flag = !PM_NotAM_flag;
|
||||
AHourTens = 0;
|
||||
AHourOnes = 1;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
// 24 hours mode increment - S
|
||||
{
|
||||
|
||||
if((AHourOnes >9) && (AHourTens < 2))
|
||||
{
|
||||
AHourOnes = 0;
|
||||
AHourTens = AHourTens +1;
|
||||
}
|
||||
|
||||
if((AHourTens ==2) && (AHourOnes == 4))
|
||||
{
|
||||
AHourOnes = 0;
|
||||
AHourTens = 0;
|
||||
}
|
||||
}
|
||||
// 24 hours mode increment - E
|
||||
// -----------*
|
||||
|
||||
/*
|
||||
if(AHourOnes >9)
|
||||
{
|
||||
AHourOnes = 0;
|
||||
AHourTens = AHourTens +1;
|
||||
if((AHourTens >1) && (A_TH_Not24_flag))
|
||||
{
|
||||
AHourTens = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(AHourTens >2)
|
||||
{
|
||||
AHourTens = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
temp = (AHourTens << 4) + AHourOnes;
|
||||
if(A_TH_Not24_flag)
|
||||
{
|
||||
bitWrite(temp, 5, A_PM_NotAM_flag);
|
||||
}
|
||||
|
||||
bitWrite(temp, 6, A_TH_Not24_flag);
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1HOUR,temp);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// Toggle Twelve and Twenty Four hour time
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void TwelveTwentyFourConvert()
|
||||
{
|
||||
|
||||
int temphours = 0;
|
||||
int temp = 0;
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_HOUR);
|
||||
HourOnes = i2cData & B00001111; //
|
||||
|
||||
// TH_Not24_flag = bitRead(i2cData, 6); // False on RTC when 24 mode selected
|
||||
// PM_NotAM_flag = bitRead(i2cData, 5);
|
||||
|
||||
if(TH_Not24_flag)
|
||||
{
|
||||
HourTens = i2cData & B00010000; //
|
||||
HourTens = HourTens >> 4;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
HourTens = i2cData & B00110000; //
|
||||
HourTens = HourTens >> 4;
|
||||
}
|
||||
|
||||
temphours = HourOnes + (HourTens*10); // 12 .... 1.2.3...12 or 0 ..1.2.3. ...23
|
||||
|
||||
if(TH_Not24_flag != NewTimeFormate)
|
||||
{
|
||||
if(NewTimeFormate) // NewTimeFormate is same formate as TH_Not24_flag where H is 12 and LOW is 24
|
||||
{
|
||||
// ---------------- 24 -> 12
|
||||
// Convert into 12 hour clock
|
||||
if(temphours >= 12)
|
||||
{
|
||||
PM_NotAM_flag = true; // it is in the PM
|
||||
if(temphours> 12)
|
||||
{
|
||||
temphours = temphours - 12; // Convert from 13:00 .... 23:00 to 1:00 ... 11:00 [Go from 23:59 / 13:00 to 12:00 to 1:00] ?
|
||||
}
|
||||
else
|
||||
{
|
||||
temphours = temphours; // do nothing it is 12:00
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PM_NotAM_flag = false; // it is in the AM - No other conversion needed
|
||||
}
|
||||
if(temphours == 0)
|
||||
{
|
||||
temphours = 12;
|
||||
}
|
||||
}
|
||||
else
|
||||
// ---------------- 12 -> 24 // Convert into 24 hour clock
|
||||
{
|
||||
if((PM_NotAM_flag == false) && (temphours == 12)) // AM only check for 00 hours
|
||||
{
|
||||
temphours = 0;
|
||||
}
|
||||
if(PM_NotAM_flag == true)
|
||||
{ // PM conversion
|
||||
if(temphours != 12) // Leave 12 as 12 in 24h time
|
||||
{
|
||||
temphours = temphours + 12;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Common finish conversion section
|
||||
TH_Not24_flag = NewTimeFormate;
|
||||
HourTens = temphours / 10;
|
||||
HourOnes = temphours % 10;
|
||||
|
||||
// ---
|
||||
temp = (HourTens << 4) + HourOnes;
|
||||
if(TH_Not24_flag)
|
||||
{
|
||||
bitWrite(temp, 5, PM_NotAM_flag);
|
||||
}
|
||||
|
||||
bitWrite(temp, 6, TH_Not24_flag);
|
||||
I2C_TX(RTCDS1337,RTC_HOUR,temp);
|
||||
|
||||
// ---
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
1449
Projects/ST_Two_Small_Clock/ST2_Routines/ST2_Routines.ino
Normal file
1449
Projects/ST_Two_Small_Clock/ST2_Routines/ST2_Routines.ino
Normal file
File diff suppressed because it is too large
Load Diff
112
Projects/ST_Two_Small_Clock/ST2_Setup/ST2_Setup.ino
Normal file
112
Projects/ST_Two_Small_Clock/ST2_Setup/ST2_Setup.ino
Normal file
@@ -0,0 +1,112 @@
|
||||
//*******************************************************************************************************************
|
||||
// Setup
|
||||
//*******************************************************************************************************************
|
||||
void setup()
|
||||
{
|
||||
|
||||
// Rows Digital pin 0 to 7
|
||||
// pinMode(0, OUTPUT); // Not used
|
||||
// pinMode(1, OUTPUT); // Not used
|
||||
|
||||
// User interface Button Pins
|
||||
/*
|
||||
digitalWrite(2, HIGH); // Write a high to pin, acts as weak pull-up
|
||||
digitalWrite(3, HIGH);
|
||||
pinMode(2, INPUT);
|
||||
pinMode(3, INPUT);
|
||||
*/
|
||||
|
||||
#if ARDUINO >= 101
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
pinMode(3, INPUT_PULLUP);
|
||||
digitalWrite(2, HIGH); // Write a high to pin, acts as weak pull-up
|
||||
digitalWrite(3, HIGH);
|
||||
#else
|
||||
digitalWrite(2, HIGH); // Write a high to pin, acts as weak pull-up
|
||||
digitalWrite(3, HIGH);
|
||||
pinMode(2, INPUT);
|
||||
pinMode(3, INPUT);
|
||||
#endif
|
||||
|
||||
// Column address bits 4 to 16 decode
|
||||
pinMode(4, OUTPUT); // DeMux A
|
||||
pinMode(5, OUTPUT); // DeMux B
|
||||
pinMode(6, OUTPUT); // DeMux C
|
||||
pinMode(7, OUTPUT); // DeMux D
|
||||
|
||||
/*
|
||||
//
|
||||
pinMode(8, OUTPUT); // ROW 1
|
||||
pinMode(9, OUTPUT); // ROW 2
|
||||
pinMode(10, OUTPUT); // ROW 3
|
||||
pinMode(11, OUTPUT); // ROW 4
|
||||
pinMode(12, OUTPUT); // ROW 5
|
||||
pinMode(13, OUTPUT); // ROW 6
|
||||
|
||||
// Make these pins outputs (Was the crystal Pins) B6 = Row 7, B7 = demux select
|
||||
DDRB = (1<<DDB7)|(1<<DDB6);
|
||||
*/
|
||||
|
||||
//test with
|
||||
DDRB = (1<<DDB7)|(1<<DDB6)|(1<<DDB5)|(1<<DDB4)|(1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0);
|
||||
|
||||
|
||||
// Make these pins outputs (analog 0 to 3)
|
||||
DDRC = DDRC | 1 << PORTC0; // Column 17
|
||||
DDRC = DDRC | 1 << PORTC1; // Column 18
|
||||
DDRC = DDRC | 1 << PORTC2; // Column 19
|
||||
DDRC = DDRC | 1 << PORTC3; // Column 20
|
||||
|
||||
|
||||
|
||||
|
||||
// attachInterrupt(0, MinuteUP, FALLING);
|
||||
// attachInterrupt(1, MinuteDOWN, FALLING);
|
||||
|
||||
// Turn one Interupts, used to update the displayed LED matrix
|
||||
Timer1.initialize(100); // was 100
|
||||
// Timer1.attachInterrupt(LEDupdate);
|
||||
Timer1.attachInterrupt(LEDupdateTHREE);
|
||||
|
||||
|
||||
// I2C Inits
|
||||
Wire.begin();
|
||||
|
||||
|
||||
// Power Reduction - S
|
||||
power_adc_disable();
|
||||
power_spi_disable();
|
||||
power_usart0_disable();
|
||||
//
|
||||
// power_timer0_disable(); // Seems required (for delay ?)
|
||||
// power_timer2_disable(); // Seems required for tone (crashes without)
|
||||
|
||||
|
||||
wdt_disable();
|
||||
|
||||
//Special
|
||||
//power_all_disable();
|
||||
//power_timer1_disable();
|
||||
|
||||
// Power Reduction - E
|
||||
|
||||
// Program specific inits
|
||||
// fillmatrix();
|
||||
delay(300);
|
||||
bval = !digitalRead(SETBUTTON);
|
||||
if(bval)
|
||||
{
|
||||
lamptest();
|
||||
}
|
||||
|
||||
displayString("v1.0");
|
||||
delay(1500);
|
||||
clearmatrix();
|
||||
|
||||
// SetStartTime(); // Basic start time of 12:00 PM
|
||||
SetAlarmTime(); // for testing
|
||||
EnableAlarm1(false); // for testing
|
||||
|
||||
SleepTimer = millis();
|
||||
|
||||
}
|
||||
137
Projects/ST_Two_Small_Clock/ST2_Sleep/ST2_Sleep.ino
Normal file
137
Projects/ST_Two_Small_Clock/ST2_Sleep/ST2_Sleep.ino
Normal file
@@ -0,0 +1,137 @@
|
||||
//*******************************************************************************************************************
|
||||
// Enter Sleep Mode
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void GoToSleep()
|
||||
{
|
||||
// SLEEP_MODE_EXT_STANDBY
|
||||
|
||||
// PORTB = (PORTB & B10000000); // Clear ROWs and De-select Demux chip
|
||||
UltraPowerDown(false);
|
||||
|
||||
attachInterrupt(0, MinuteUP, FALLING);
|
||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // was (SLEEP_MODE_EXT_STANDBY);
|
||||
cli();
|
||||
// if (some_condition)
|
||||
// {
|
||||
sleep_enable();
|
||||
// sleep_bod_disable();
|
||||
sei();
|
||||
sleep_cpu();
|
||||
// _NOP();
|
||||
// _NOP();
|
||||
sleep_disable();
|
||||
// }
|
||||
sei();
|
||||
|
||||
detachInterrupt(0);
|
||||
|
||||
UltraPowerDown(true);
|
||||
|
||||
blinkFlag = false; // Incase sleep started during time set
|
||||
// MODEOVERRIDEFLAG = false;
|
||||
NextStateFlag = false;
|
||||
|
||||
NextStateRequest = false;
|
||||
NextSUBStateRequest = false;
|
||||
|
||||
SetTimeFlag = false;
|
||||
// SetDigit = 4;
|
||||
|
||||
STATE = 0;
|
||||
SUBSTATE = 0;
|
||||
JustWokeUpFlag = true;
|
||||
|
||||
// CheckAlarm();
|
||||
// if(ALARM1FLAG)
|
||||
// {
|
||||
// ALARM1FLAG = false;
|
||||
// EnableAlarm1(false);
|
||||
// STATE = 90;
|
||||
// }
|
||||
|
||||
// displayString("Wake");
|
||||
// delay(1000);
|
||||
// clearmatrix();
|
||||
|
||||
SleepTimer = millis();
|
||||
|
||||
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// MAX power Savings
|
||||
//*******************************************************************************************************************
|
||||
void UltraPowerDown(boolean onoff)
|
||||
{
|
||||
if(onoff) // True = full power mode = ON
|
||||
{
|
||||
// pinMode(4, OUTPUT); // DeMux A
|
||||
// pinMode(5, OUTPUT); // DeMux B
|
||||
// pinMode(6, OUTPUT); // DeMux C
|
||||
// pinMode(7, OUTPUT); // DeMux D
|
||||
|
||||
power_timer1_enable(); // Used for LED matrix refresh
|
||||
power_timer0_enable(); // Seems required (for delay ?)
|
||||
power_timer2_enable(); // Seems required for tone (crashes without)
|
||||
|
||||
power_twi_enable();
|
||||
}
|
||||
else // False is LOW Power mode
|
||||
{
|
||||
// LED MATRIX
|
||||
//
|
||||
// Port C: C0 to C3 set to high. Columns 17 to 20 of LED matrix - Cathode connection
|
||||
PORTC = (PORTC & B11110000) | B00001111;
|
||||
|
||||
// Port B: Unselect the MUX chip
|
||||
PORTB = (1<<PORTB7);
|
||||
// Port B: Set all the ROWs to high: High on both cathode and annode = no current ?
|
||||
PORTB = PORTB | B01111111; // Could be PORTB =B11111111;
|
||||
|
||||
// pinMode(4, INPUT); // DeMux A // Set these to inputs to lower current on mux inputs
|
||||
// pinMode(5, INPUT); // DeMux B
|
||||
// pinMode(6, INPUT); // DeMux C
|
||||
// pinMode(7, INPUT); // DeMux D
|
||||
|
||||
PORTD = (PORTD & B00001111) | B11110000 ; // SET all address pins
|
||||
|
||||
|
||||
// Other Peripherals
|
||||
//
|
||||
power_timer1_disable(); // Used for LED matrix refresh
|
||||
power_timer0_disable(); // Seems required (for delay ?)
|
||||
power_timer2_disable(); // Seems required for tone (crashes without)
|
||||
|
||||
power_twi_disable();
|
||||
|
||||
PORTC = PORTC | 1 << PORTC4; // Set SDA and SCL to high so they do not pull current from external pull-up
|
||||
PORTC = PORTC | 1 << PORTC5;
|
||||
|
||||
DDRC = DDRC | 1 << PORTC4; // Make SDA and SCL inputs = lower current
|
||||
DDRC = DDRC | 1 << PORTC5; //
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// WAKE-UP - Called by Interrupt 0 on Digital pin 2
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void MinuteUP()
|
||||
{
|
||||
MINUP = true;
|
||||
}
|
||||
|
||||
/*
|
||||
void MinuteDOWN()
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
void ResetSleepCount()
|
||||
{
|
||||
SleepTimer = millis();
|
||||
}
|
||||
|
||||
25
Projects/ST_Two_Small_Clock/ST2_TWI/ST2_TWI.ino
Normal file
25
Projects/ST_Two_Small_Clock/ST2_TWI/ST2_TWI.ino
Normal file
@@ -0,0 +1,25 @@
|
||||
//*******************************************************************************************************************
|
||||
// I2C TX RX
|
||||
//*******************************************************************************************************************
|
||||
void I2C_TX(byte device, byte regadd, byte tx_data) // Transmit I2C Data
|
||||
{
|
||||
Wire.beginTransmission(device);
|
||||
Wire.write(regadd);
|
||||
Wire.write(tx_data);
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
void I2C_RX(byte devicerx, byte regaddrx) // Receive I2C Data
|
||||
{
|
||||
Wire.beginTransmission(devicerx);
|
||||
Wire.write(regaddrx);
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(int(devicerx), 1);
|
||||
|
||||
byte c = 0;
|
||||
if(Wire.available())
|
||||
{
|
||||
i2cData = Wire.read();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,356 @@
|
||||
|
||||
|
||||
// *****************************************************************************************************************
|
||||
// * *
|
||||
// * SpikenzieLabs.com *
|
||||
// * *
|
||||
// * Solder:Time Desk Clock *
|
||||
// * *
|
||||
// *****************************************************************************************************************
|
||||
//
|
||||
// BY: MARK DEMERS
|
||||
// May 2013
|
||||
// VERSION 1.0
|
||||
//
|
||||
// Brief:
|
||||
// Sketch used in the Solder: Time Desk Clock Kit, more info and build instructions at http://www.spikenzielabs.com/stdc
|
||||
//
|
||||
//
|
||||
// LEGAL:
|
||||
// This code is provided as is. No guaranties or warranties are given in any form. It is your responsibilty to
|
||||
// determine this codes suitability for your application.
|
||||
//
|
||||
// Changes:
|
||||
// A. Modified LEDupdateTHREE() void used by ST:2 Watch to function with the new circuits in the Solder:Time Desk Clock
|
||||
// B. Modified port dirctions on some pins to deal with new circuits.
|
||||
// C. Changed sleep mode into a "change back to display time" mode
|
||||
|
||||
#include <Wire.h>
|
||||
#include <EEPROM.h>
|
||||
|
||||
#include <TimerOne.h>
|
||||
|
||||
#include <avr/sleep.h>
|
||||
#include <avr/power.h>
|
||||
#include <avr/wdt.h>
|
||||
|
||||
// Worm animation
|
||||
int c =0;
|
||||
int y = 3;
|
||||
int target = 3;
|
||||
int targdist =0;
|
||||
boolean targdir = true;
|
||||
int wormlenght = 15;
|
||||
boolean soundeffect = false;
|
||||
|
||||
// int i =0;
|
||||
// int i2 =0;
|
||||
// int vite = 2;
|
||||
// uint8_t incro = 0;
|
||||
// uint8_t column = 0;
|
||||
uint8_t TEXT = 65;
|
||||
uint8_t i2cData = 0;
|
||||
// int nextcounter = 0;
|
||||
|
||||
int STATE = 0;
|
||||
int SUBSTATE = 0;
|
||||
int MAXSTATE = 6;
|
||||
boolean NextStateRequest = false;
|
||||
boolean NextSUBStateRequest = false;
|
||||
boolean JustWokeUpFlag = false;
|
||||
boolean JustWokeUpFlag2= false;
|
||||
boolean OptionModeFlag = false;
|
||||
|
||||
int ROWBITINDEX = 0;
|
||||
int scrollCounter =0;
|
||||
int ScrollLoops = 3;
|
||||
int scrollSpeed = 300; // was 1200
|
||||
int blinkCounter = 0;
|
||||
boolean blinkFlag = false;
|
||||
boolean blinkON = true;
|
||||
boolean blinkHour = false;
|
||||
boolean blinkMin = false;
|
||||
#define blinkTime 500 // was 1000
|
||||
|
||||
boolean displayFLAG = true;
|
||||
|
||||
unsigned long SleepTimer;
|
||||
unsigned long currentMillis;
|
||||
unsigned long SleepLimit = 6000;
|
||||
boolean SleepEnable = true;
|
||||
int UpdateTime = 0;
|
||||
|
||||
#define BUTTON1 2
|
||||
#define MODEBUTTON 2
|
||||
#define BUTTON2 3
|
||||
#define SETBUTTON 3
|
||||
boolean bval = false;
|
||||
|
||||
//char Str1[] = "Hi";
|
||||
char IncomingMessage[24];
|
||||
char MessageRead;
|
||||
//uint8_t INBYTE;
|
||||
uint8_t Message[275];
|
||||
int IncomingIndex = 0;
|
||||
int IncomingMessIndex =0;
|
||||
int IncomingMax = 0;
|
||||
int MessagePointer = 0;
|
||||
int StartWindow = 0;
|
||||
int IncomingLoaded =0;
|
||||
|
||||
|
||||
char days[7][4] = {
|
||||
"Sun","Mon","Tue","Wed","Thr","Fri","Sat"};
|
||||
char months[12][4] = {
|
||||
"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
|
||||
|
||||
// Time Variables
|
||||
uint8_t HourTens = 1;
|
||||
uint8_t HourOnes = 2;
|
||||
uint8_t MinTens = 0;
|
||||
uint8_t MinOnes = 0;
|
||||
uint8_t SecTens = 0;
|
||||
uint8_t SecOnes = 0;
|
||||
|
||||
uint8_t Days =1;
|
||||
uint8_t DateOnes = 1;
|
||||
uint8_t DateTens =0;
|
||||
uint8_t MonthOnes =1;
|
||||
uint8_t MonthTens = 1;
|
||||
uint8_t YearsOnes = 2;
|
||||
uint8_t YearsTens = 1;
|
||||
|
||||
uint8_t DayCode =1;
|
||||
uint8_t MonthCode =1;
|
||||
|
||||
|
||||
boolean TH_Not24_flag = true;
|
||||
boolean PM_NotAM_flag = false;
|
||||
boolean NewTimeFormate = TH_Not24_flag;
|
||||
uint8_t AMPMALARMDOTS = 0;
|
||||
|
||||
// Alarm
|
||||
uint8_t AHourTens = 1;
|
||||
uint8_t AHourOnes = 2;
|
||||
uint8_t AMinTens = 0;
|
||||
uint8_t AMinOnes = 0;
|
||||
|
||||
boolean A_TH_Not24_flag = true;
|
||||
boolean A_PM_NotAM_flag = false;
|
||||
|
||||
// StopWatch
|
||||
int OldTime = 0;
|
||||
int CurrentTime = 0;
|
||||
int TotalTime = 0;
|
||||
|
||||
uint8_t SWDigit4 = 0;
|
||||
uint8_t SWDigit3 = 0;
|
||||
uint8_t SWDigit2 = 0;
|
||||
uint8_t SWDigit1 = 0;
|
||||
|
||||
int SWMINUTES = 0;
|
||||
int SWSECONDS = 0;
|
||||
|
||||
int dayIndex = 0;
|
||||
|
||||
//uint8_t SetDigit = 4;
|
||||
//boolean MODEOVERRIDEFLAG = false;
|
||||
boolean NextStateFlag = false;
|
||||
boolean SetTimeFlag = false;
|
||||
boolean ALARM1FLAG = false;
|
||||
boolean ALARMON = false;
|
||||
|
||||
boolean scrollDirFlag = false;
|
||||
|
||||
|
||||
//
|
||||
volatile uint8_t Mcolumn = 0;
|
||||
//volatile uint8_t McolumnTemp = 0;
|
||||
//volatile uint8_t Mrow = 0;
|
||||
volatile uint8_t LEDMAT[20];
|
||||
|
||||
volatile boolean MINUP = false;
|
||||
volatile boolean MINDOWN = false;
|
||||
volatile boolean TFH = false;
|
||||
|
||||
const int digitoffset = 95; // 95 // was 16
|
||||
|
||||
|
||||
// Constants
|
||||
// DS1337+ Address locations
|
||||
#define RTCDS1337 B01101000 // was B11010000
|
||||
#define RTCCONT B00001110 //; Control
|
||||
#define RTCSTATUS B00001111 //; Status
|
||||
|
||||
//#define RTC_HSEC B00000001 //; Hundredth of a secound
|
||||
#define RTC_SEC B00000000 //; Seconds
|
||||
#define RTC_MIN B00000001 //; Minuites
|
||||
#define RTC_HOUR B00000010 //; Hours
|
||||
|
||||
#define RTC_DAY B00000011 //; Day
|
||||
#define RTC_DATE B00000100 //; Date
|
||||
#define RTC_MONTH B00000101 //; Month
|
||||
#define RTC_YEAR B00000110 //; Year
|
||||
|
||||
#define RTC_ALARM1SEC B00000111 //; Seconds
|
||||
#define RTC_ALARM1MIN B00001000 //; Minuites
|
||||
#define RTC_ALARM1HOUR B00001001 //; Hours
|
||||
#define RTC_ALARM1DATE B00001010 //; Date
|
||||
|
||||
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// Bit Map Letter - data array
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// const byte LETTERS[95][5] = {
|
||||
const byte LETTERS[106][5] = {
|
||||
0,0,0,0,0, // Space
|
||||
0,0,95,0,0, // !
|
||||
0,3,0,3,0, // "
|
||||
18,63,18,63,18, // #
|
||||
4,42,127,42,16, // $
|
||||
34,21,42,84,34, // %
|
||||
54,73,81,34,80, // &
|
||||
0,0,3,0,0, // '
|
||||
0,28,34,65,0, // (
|
||||
0,65,34,28,0, // (
|
||||
4,20,15,20,4, // *
|
||||
8,8,62,8,8, // +
|
||||
0,0,2,1,0, // ' (not sure)
|
||||
8,8,8,8,8, // -
|
||||
0,0,64,0,0, // .
|
||||
32,16,8,4,2, // /
|
||||
|
||||
62,65,65,65,62, // 0
|
||||
64,66,127,64,64, // 1
|
||||
98,81,73,73,70, // 2
|
||||
34,65,73,73,54, // 3
|
||||
7,8,8,127,8, // 4
|
||||
47,73,73,73,49, // 5
|
||||
62,73,73,73,50, // 6
|
||||
65,33,17,9,7, // 7
|
||||
54,73,73,73,54, // 8
|
||||
6,9,9,9,126, // 9
|
||||
|
||||
0,0,54,0,0, // :
|
||||
0,64,54,0,0, // ;
|
||||
8,20,34,65,0, // <
|
||||
20,20,20,20,20, // =
|
||||
0,65,34,20,8, // >
|
||||
6,1,81,9,6, // ?
|
||||
62,65,73,85,10, // @
|
||||
|
||||
124,10,9,10,124, // A
|
||||
127,73,73,73,54, // B
|
||||
62,65,65,65,34, // C
|
||||
127,65,65,65,62, // D
|
||||
127,73,73,73,65, // E
|
||||
127,9,9,9,1, // F
|
||||
62,65,73,73,50, // G
|
||||
127,8,8,8,127, // H
|
||||
0,65,127,65,0, // I was 65,65,127,65,65,
|
||||
32,64,65,63,1, // J
|
||||
127,8,20,34,65, // K
|
||||
127,64,64,64,64, // L
|
||||
127,2,4,2,127, // M
|
||||
127,4,8,16,127, // N
|
||||
62,65,65,65,62, // O
|
||||
127,9,9,9,6, // P
|
||||
62,65,81,33,94, // Q
|
||||
127,9,25,41,70, // R
|
||||
38,73,73,73,50, // S
|
||||
1,1,127,1,1, // T
|
||||
63,64,64,64,63, // U
|
||||
31,32,64,32,31, // V
|
||||
63,64,48,64,63, // W
|
||||
99,20,8,20,99, // X
|
||||
3,4,120,4,3, // Y
|
||||
97,81,73,69,67, // Z
|
||||
|
||||
0,127,65,65,0, // [
|
||||
2,4,8,16,32, // back slash
|
||||
0,65,65,127,0, // ]
|
||||
0,2,1,2,0, // ^
|
||||
128,128,128,128,128, // _
|
||||
0,0,1,2,0, // `
|
||||
|
||||
112,72,72,40,120, // a
|
||||
126,48,72,72,48, // b
|
||||
48,72,72,72,72, // c
|
||||
48,72,72,48,126, // d
|
||||
56,84,84,84,88, // e
|
||||
0,8,124,10,0, // f
|
||||
36,74,74,74,60, // g
|
||||
126,8,8,8,112, // h
|
||||
0,0,122,0,0, // i
|
||||
32,64,66,62,2, // j
|
||||
124,16,16,40,68, // k
|
||||
0,124,64,64,0, // l
|
||||
120,4,120,4,120, // m
|
||||
124,8,4,4,120, // n
|
||||
48,72,72,72,48, // o
|
||||
126,18,18,18,12, // p
|
||||
12,18,18,18,124, // q
|
||||
124,8,4,4,8, // r
|
||||
72,84,84,84,36, // s
|
||||
4,4,126,4,4, // t
|
||||
60,64,64,64,60, // u
|
||||
28,32,64,32,28, // v
|
||||
124,32,16,32,124, // w
|
||||
68,40,16,40,68, // x
|
||||
4,8,112,8,4, // y
|
||||
68,100,84,76,68, // z
|
||||
|
||||
0,8,54,65,0, // {
|
||||
0,0,127,0,0, // |
|
||||
0,65,54,8,0, // }
|
||||
16,8,24,16,8, // ~
|
||||
|
||||
// Small Numbers (for adding colon in clock applications)
|
||||
0,62,34,62,0, // 0
|
||||
0,0,62,0,0, // 1
|
||||
0,58,42,46,0, // 2
|
||||
0,42,42,62,0, // 3
|
||||
0,14,8,62,0, // 4
|
||||
0,46,42,58,0, // 5
|
||||
0,62,42,58,0, // 6
|
||||
0,2,2,62,0, // 7
|
||||
0,62,42,62,0, // 8
|
||||
0,14,10,62,0, // 9
|
||||
0,0,20,0,0, // :
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
const byte GRAPHIC[5][5] = {
|
||||
0,0,0,0,0,
|
||||
0,28,62,127,0, // Speaker cone
|
||||
34,28,65,34,28, // Sound wave
|
||||
16,32,16,8,4, // Check mark
|
||||
34,20,8,20,34, // "X"
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
29
Projects/Servo_Sweep/Servo_Sweep.ino
Executable file
29
Projects/Servo_Sweep/Servo_Sweep.ino
Executable file
@@ -0,0 +1,29 @@
|
||||
// Sweep
|
||||
// by BARRAGAN
|
||||
|
||||
#include <Servo.h>
|
||||
|
||||
Servo myservo; // create servo object to control a servo
|
||||
// a maximum of eight servo objects can be created
|
||||
|
||||
int pos = 0; // variable to store the servo position
|
||||
|
||||
void setup()
|
||||
{
|
||||
myservo.attach(9); // attaches the servo on pin 9 to the servo object
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
|
||||
{ // in steps of 1 degree
|
||||
myservo.write(pos); // tell servo to go to position in variable 'pos'
|
||||
delay(15); // waits 15ms for the servo to reach the position
|
||||
}
|
||||
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
|
||||
{
|
||||
myservo.write(pos); // tell servo to go to position in variable 'pos'
|
||||
delay(15); // waits 15ms for the servo to reach the position
|
||||
}
|
||||
}
|
||||
93
Projects/StepMotor/StepMotor.ino
Executable file
93
Projects/StepMotor/StepMotor.ino
Executable file
@@ -0,0 +1,93 @@
|
||||
/* -----------------------------------------------------------
|
||||
* | Arduino Experimentation Kit Example Code |
|
||||
* | CIRC-03 .: Spin Motor Spin :. (Transistor and Motor) |
|
||||
* -----------------------------------------------------------
|
||||
*
|
||||
* The Arduinos pins are great for driving LEDs however if you hook
|
||||
* up something that requires more power you will quickly break them.
|
||||
* To control bigger items we need the help of a transistor.
|
||||
* Here we will use a transistor to control a small toy motor
|
||||
*
|
||||
* http://tinyurl.com/d4wht7
|
||||
*
|
||||
*/
|
||||
|
||||
int motorPin = 9; // define the pin the motor is connected to
|
||||
// (if you use pin 9,10,11 or 3you can also control speed)
|
||||
|
||||
/*
|
||||
* setup() - this function runs once when you turn your Arduino on
|
||||
* We set the motors pin to be an output (turning the pin high (+5v) or low (ground) (-))
|
||||
* rather than an input (checking whether a pin is high or low)
|
||||
*/
|
||||
void setup()
|
||||
{
|
||||
pinMode(motorPin, OUTPUT);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* loop() - this function will start after setup finishes and then repeat
|
||||
* we call a function called motorOnThenOff()
|
||||
*/
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
motorOnThenOff();
|
||||
//motorOnThenOffWithSpeed();
|
||||
//motorAcceleration();
|
||||
}
|
||||
|
||||
/*
|
||||
* motorOnThenOff() - turns motor on then off
|
||||
* (notice this code is identical to the code we used for
|
||||
* the blinking LED)
|
||||
*/
|
||||
void motorOnThenOff(){
|
||||
int onTime = 2500; //the number of milliseconds for the motor to turn on for
|
||||
int offTime = 1000; //the number of milliseconds for the motor to turn off for
|
||||
|
||||
digitalWrite(motorPin, HIGH); // turns the motor On
|
||||
delay(onTime); // waits for onTime milliseconds
|
||||
digitalWrite(motorPin, LOW); // turns the motor Off
|
||||
delay(offTime); // waits for offTime milliseconds
|
||||
}
|
||||
|
||||
/*
|
||||
* motorOnThenOffWithSpeed() - turns motor on then off but uses speed values as well
|
||||
* (notice this code is identical to the code we used for
|
||||
* the blinking LED)
|
||||
*/
|
||||
void motorOnThenOffWithSpeed(){
|
||||
|
||||
int onSpeed = 200; // a number between 0 (stopped) and 255 (full speed)
|
||||
int onTime = 2500; //the number of milliseconds for the motor to turn on for
|
||||
|
||||
int offSpeed = 50; // a number between 0 (stopped) and 255 (full speed)
|
||||
int offTime = 1000; //the number of milliseconds for the motor to turn off for
|
||||
|
||||
analogWrite(motorPin, onSpeed); // turns the motor On
|
||||
delay(onTime); // waits for onTime milliseconds
|
||||
analogWrite(motorPin, offSpeed); // turns the motor Off
|
||||
delay(offTime); // waits for offTime milliseconds
|
||||
}
|
||||
|
||||
/*
|
||||
* motorAcceleration() - accelerates the motor to full speed then
|
||||
* back down to zero
|
||||
*/
|
||||
void motorAcceleration(){
|
||||
int delayTime = 50; //milliseconds between each speed step
|
||||
|
||||
//Accelerates the motor
|
||||
for(int i = 0; i < 256; i++){ //goes through each speed from 0 to 255
|
||||
analogWrite(motorPin, i); //sets the new speed
|
||||
delay(delayTime); // waits for delayTime milliseconds
|
||||
}
|
||||
|
||||
//Decelerates the motor
|
||||
for(int i = 255; i >= 0; i--){ //goes through each speed from 255 to 0
|
||||
analogWrite(motorPin, i); //sets the new speed
|
||||
delay(delayTime); // waits for delayTime milliseconds
|
||||
}
|
||||
}
|
||||
31
Projects/Tea-duino Main/Joystick_DirectionPrint/Joystick_DirectionPrint.ino
Executable file
31
Projects/Tea-duino Main/Joystick_DirectionPrint/Joystick_DirectionPrint.ino
Executable file
@@ -0,0 +1,31 @@
|
||||
int UD = 0;
|
||||
int LR = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
UD = analogRead(A0);
|
||||
LR = analogRead(A1);
|
||||
if (UD == 0)
|
||||
{
|
||||
Serial.println("This is down!");
|
||||
}
|
||||
else
|
||||
if (UD == 1023)
|
||||
{
|
||||
Serial.println("This is up!");
|
||||
}
|
||||
else
|
||||
if (LR == 0)
|
||||
{
|
||||
Serial.println("This is Left!");
|
||||
}
|
||||
else
|
||||
if (LR == 1023)
|
||||
{
|
||||
Serial.println("This is Right!");
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
72
Projects/Tea-duino Main/Menusystem_LCD/Menusystem_LCD.ino
Executable file
72
Projects/Tea-duino Main/Menusystem_LCD/Menusystem_LCD.ino
Executable file
@@ -0,0 +1,72 @@
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
|
||||
int UD = 0;
|
||||
int LR = 0;
|
||||
const int buttonPin = 2;
|
||||
|
||||
char* myString [] = {"@EchoEsq", "@SindreIvers", "@KevinMidboe", "@Odinbn", "@hozar132"};
|
||||
int length = 0;
|
||||
|
||||
int buttonState = 0;
|
||||
|
||||
int i = 0;
|
||||
|
||||
void setup(){
|
||||
lcd.begin(16, 2);
|
||||
|
||||
pinMode(buttonPin, INPUT);
|
||||
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
//Get length of myString
|
||||
length = 5;
|
||||
|
||||
UD = analogRead(0);
|
||||
LR = analogRead(1);
|
||||
/*
|
||||
if (UD > 512)
|
||||
{
|
||||
Serial.print("UP");
|
||||
delay(800);
|
||||
}
|
||||
else
|
||||
if (UD < 512)
|
||||
{
|
||||
Serial.print("Down");
|
||||
delay(800);
|
||||
}
|
||||
else
|
||||
if (LR < 512 && UD > 512)
|
||||
{
|
||||
Serial.print("Right");
|
||||
delay(800);
|
||||
}
|
||||
else
|
||||
if (LR < 512)
|
||||
{
|
||||
Serial.print("Left");
|
||||
delay(800);
|
||||
}*/
|
||||
|
||||
buttonState = digitalRead(buttonPin);
|
||||
if (buttonState == HIGH)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write(">");
|
||||
lcd.write(myString[i]);
|
||||
lcd.setCursor(1,1);
|
||||
lcd.write(myString[i + 1]);
|
||||
delay(800);
|
||||
i++;
|
||||
}
|
||||
if (i >= length)
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
BIN
Projects/Tea-duino Main/Menusystem_LCD/data/JoystickController.zip
Executable file
BIN
Projects/Tea-duino Main/Menusystem_LCD/data/JoystickController.zip
Executable file
Binary file not shown.
BIN
Projects/Tea-duino Main/Schematics/Screen Shot 2014-05-11 at 22.08.05.png
Executable file
BIN
Projects/Tea-duino Main/Schematics/Screen Shot 2014-05-11 at 22.08.05.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 200 KiB |
BIN
Projects/Tea-duino Main/Schematics/Tea-Duino Schematic.fzz
Executable file
BIN
Projects/Tea-duino Main/Schematics/Tea-Duino Schematic.fzz
Executable file
Binary file not shown.
60
Projects/Tea-duino Main/SimplePost/SimplePost.ino
Executable file
60
Projects/Tea-duino Main/SimplePost/SimplePost.ino
Executable file
@@ -0,0 +1,60 @@
|
||||
#include <SPI.h> // needed in Arduino 0019 or later
|
||||
#include <Ethernet.h>
|
||||
#include <Twitter.h>
|
||||
|
||||
// The includion of EthernetDNS is not needed in Arduino IDE 1.0 or later.
|
||||
// Please uncomment below in Arduino IDE 0022 or earlier.
|
||||
//#include <EthernetDNS.h>
|
||||
|
||||
|
||||
// Ethernet Shield Settings
|
||||
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xA7, 0x51 };
|
||||
|
||||
const int buttonPin = 9;
|
||||
int buttonState = 0;
|
||||
|
||||
// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
|
||||
//byte ip[] = { 192, 168, 2, 250 };
|
||||
|
||||
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
|
||||
Twitter twitter("2307428619-jTdwfFJ4r9aYuaYHQ2YeqBWQNOy6nSg6aTRequb");
|
||||
|
||||
// Message to post
|
||||
char msg[] = "@KevinMidboe Vannet er ferdig!";
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
Ethernet.begin(mac);
|
||||
// or you can use DHCP for autoomatic IP address configuration.
|
||||
// Ethernet.begin(mac);
|
||||
Serial.begin(9600);
|
||||
Serial.println("Ready!");
|
||||
pinMode(buttonPin, INPUT);
|
||||
buttonState = LOW;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
buttonState = digitalRead(buttonPin);
|
||||
if (buttonState == HIGH)
|
||||
{
|
||||
Serial.println("connecting ...");
|
||||
if (twitter.post(msg)) {
|
||||
// Specify &Serial to output received response to Serial.
|
||||
// If no output is required, you can just omit the argument, e.g.
|
||||
// int status = twitter.wait();
|
||||
int status = twitter.wait(&Serial);
|
||||
if (status == 200) {
|
||||
Serial.println("OK.");
|
||||
} else {
|
||||
Serial.print("failed : code ");
|
||||
Serial.println(status);
|
||||
}
|
||||
} else {
|
||||
Serial.println("connection failed.");
|
||||
}
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
315
Projects/Tea-duino Main/Tea-duino 2.0.pde
Executable file
315
Projects/Tea-duino Main/Tea-duino 2.0.pde
Executable file
@@ -0,0 +1,315 @@
|
||||
#include <LiquidCrystal.h>
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <Twitter.h>
|
||||
|
||||
LiquidCrystal lcd(0, 1, 2, 6, 7, 8);
|
||||
|
||||
char *menuTree[] = {"mainMenu", "Users", "Add user"};
|
||||
char *mainMenu[] = {"Choose user", "Add user"};
|
||||
char *twitterHandles[] = {"@EchoEsq", "@SindreIvers", "@KevinMidboe", "@Odinbn", "@Hozar132"};
|
||||
char *itsDone[] = {"Vannet er ferdig!", "TEATIME!", "my Man, the water is done!"};
|
||||
|
||||
char *errorWhereIsBoiler [] = {"Sett vannkokeren", "pa knappen."};
|
||||
char *startWaterMessage [] = {"Skru pa vannet!"};
|
||||
|
||||
byte CoffeeEmpty[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b10001, 0b10001, 0b10001, 0b01110};
|
||||
|
||||
byte CoffeeHank[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b00000,
|
||||
0b11000, 0b01000, 0b11000, 0b00000};
|
||||
|
||||
byte Coffee1[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b10001, 0b10001, 0b11111, 0b01110};
|
||||
|
||||
byte Coffee2[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b10001, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
byte Coffee3[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b11111, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
byte CoffeeSmoke1[8] = {
|
||||
0b00101, 0b01010, 0b00101, 0b11111,
|
||||
0b11111, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
byte CoffeeSmoke2[8] = {
|
||||
0b01010, 0b00101, 0b01010, 0b11111,
|
||||
0b11111, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
Twitter twitter("2307428619-TIM5H7Lh6L9HrrQLMynR5cinWpNbiUTt2827myM");
|
||||
byte mac[] = {0x90, 0xA2, 0xDa, 0x0d, 0xA7, 0x51};
|
||||
|
||||
const int buttonPin = 3;
|
||||
int resetPin = 9;
|
||||
int buttonState = 0;
|
||||
int UD = 1;
|
||||
int LR = 1;
|
||||
|
||||
boolean movedDown = false;
|
||||
int upDownCount = 0;
|
||||
int menuSelector = 0;
|
||||
int mainMenuController = 0;
|
||||
int animationSelector = 2;
|
||||
|
||||
char* username;
|
||||
|
||||
int lengthMainMenu = sizeof(mainMenu);
|
||||
int lengthUserMenu = sizeof(twitterHandles);
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(resetPin, OUTPUT);
|
||||
|
||||
lcd.begin(16,2);
|
||||
Ethernet.begin(mac);
|
||||
|
||||
lcd.createChar(1, CoffeeHank);
|
||||
lcd.createChar(2, CoffeeEmpty);
|
||||
lcd.createChar(3, Coffee1);
|
||||
lcd.createChar(4, Coffee2);
|
||||
lcd.createChar(5, Coffee3);
|
||||
lcd.createChar(6, CoffeeSmoke1);
|
||||
lcd.createChar(7, CoffeeSmoke2);
|
||||
|
||||
pinMode(buttonPin, INPUT);
|
||||
|
||||
upDownCount = writeMainMenu(movedDown, upDownCount);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
while (menuTree[menuSelector] == menuTree[0])
|
||||
{
|
||||
delay(200);
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
if (UD == 0)
|
||||
{
|
||||
movedDown = false;
|
||||
upDownCount--;
|
||||
if (upDownCount < 0)
|
||||
{
|
||||
upDownCount = 0;
|
||||
}
|
||||
upDownCount = writeMainMenu(movedDown, upDownCount);
|
||||
}
|
||||
if (UD == 1022)
|
||||
{
|
||||
movedDown = true;
|
||||
upDownCount = writeMainMenu(movedDown, upDownCount);
|
||||
upDownCount++;
|
||||
}
|
||||
if (LR == 0)
|
||||
{
|
||||
menuSelector = 1;
|
||||
upDownCount = 0;
|
||||
upDownCount = writeUserMenu(movedDown, upDownCount);
|
||||
delay(400);
|
||||
}
|
||||
}
|
||||
while (menuTree[menuSelector] == menuTree[1])
|
||||
{
|
||||
delay(200);
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
if (UD == 0)
|
||||
{
|
||||
movedDown = false;
|
||||
upDownCount--;
|
||||
if (upDownCount < 0)
|
||||
{
|
||||
upDownCount = 0;
|
||||
}
|
||||
upDownCount = writeUserMenu(movedDown, upDownCount);
|
||||
}
|
||||
if (UD == 1022)
|
||||
{
|
||||
movedDown = true;
|
||||
upDownCount = writeUserMenu(movedDown, upDownCount);
|
||||
upDownCount++;
|
||||
}
|
||||
if (LR == 0)
|
||||
{
|
||||
username = twitterHandles[upDownCount];
|
||||
buttonState = digitalRead(buttonPin);
|
||||
if (buttonState == LOW)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write(errorWhereIsBoiler[0]);
|
||||
lcd.setCursor(0,1);
|
||||
lcd.write(errorWhereIsBoiler[1]);
|
||||
delay(2000);
|
||||
upDownCount = writeUserMenu(movedDown, upDownCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkWaterON(username);
|
||||
}
|
||||
}
|
||||
if (LR == 1022)
|
||||
{
|
||||
menuSelector = 0;
|
||||
upDownCount = 0;
|
||||
upDownCount = writeMainMenu(movedDown, upDownCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int writeMainMenu(boolean movedDown, int upDownCount)
|
||||
{
|
||||
int i = upDownCount;
|
||||
|
||||
lcd.clear();
|
||||
|
||||
if (movedDown == false)
|
||||
{
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(1,1);
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
lcd.setCursor(1,0);
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(0,1);
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int writeUserMenu(boolean movedDown, int upDownCount)
|
||||
{
|
||||
int i = upDownCount;
|
||||
|
||||
lcd.clear();
|
||||
|
||||
if (movedDown == false)
|
||||
{
|
||||
lcd.write(">");
|
||||
lcd.write(twitterHandles[i]);
|
||||
lcd.setCursor(1,1);
|
||||
lcd.write(twitterHandles[i + 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
lcd.setCursor(1,0);
|
||||
lcd.write(twitterHandles[i]);
|
||||
lcd.setCursor(0,1);
|
||||
lcd.write(">");
|
||||
lcd.write(twitterHandles[i + 1]);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void checkWaterON(char* username)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write(startWaterMessage[0]);
|
||||
delay(1500);
|
||||
|
||||
buttonState = digitalRead(buttonPin);
|
||||
if (buttonState == LOW)
|
||||
{
|
||||
waterOnAndTweet(username);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkWaterON(username);
|
||||
}
|
||||
}
|
||||
|
||||
void waterOnAndTweet(char* username)
|
||||
{
|
||||
buttonState = digitalRead(buttonPin);
|
||||
while (buttonState == LOW)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.setCursor(6, 1);
|
||||
lcd.write(animationSelector);
|
||||
lcd.setCursor(7, 1);
|
||||
lcd.write(1);
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(animationSelector);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
animationSelector++;
|
||||
delay(1500);
|
||||
if (animationSelector == 6)
|
||||
{
|
||||
animationSelector = 2;
|
||||
}
|
||||
waterOnAndTweet(username);
|
||||
}
|
||||
if (twitter.post(username))
|
||||
{
|
||||
int status = twitter.wait(&lcd);
|
||||
if (status == 200)
|
||||
{
|
||||
waitForPickup();
|
||||
}
|
||||
else
|
||||
if(status == 403)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write("Duplicate tweet!");
|
||||
lcd.setCursor(0,1);
|
||||
lcd.write(status);
|
||||
delay(65000);
|
||||
twitter.post(username);
|
||||
|
||||
// int status = twitter.wait(&lcd);
|
||||
// if(status == 200)
|
||||
// {
|
||||
// waitForPickup();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// waterOnAndTweet(username);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void waitForPickup()
|
||||
{
|
||||
buttonState = digitalRead(buttonPin);
|
||||
while (buttonState == HIGH)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.setCursor(6, 1);
|
||||
lcd.write(6);
|
||||
lcd.setCursor(7, 1);
|
||||
lcd.write(1);
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(6);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
|
||||
delay(1500);
|
||||
lcd.clear();
|
||||
lcd.setCursor(6, 1);
|
||||
lcd.write(7);
|
||||
lcd.setCursor(7, 1);
|
||||
lcd.write(1);
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(7);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
delay(1500);
|
||||
waitForPickup();
|
||||
}
|
||||
while (buttonState == LOW)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write("RESET!");
|
||||
digitalWrite(resetPin, HIGH);
|
||||
delay(3000);
|
||||
}
|
||||
}
|
||||
284
Projects/Tea-duino Main/Tea-duino.pde
Executable file
284
Projects/Tea-duino Main/Tea-duino.pde
Executable file
@@ -0,0 +1,284 @@
|
||||
#include <LiquidCrystal.h>
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <Twitter.h>
|
||||
|
||||
LiquidCrystal lcd(0, 1, 2, 6, 7, 8);
|
||||
|
||||
char *mainMenu[] = {"Choose user", "Add new user"};
|
||||
char *twitterHandles[] = {"@EchoEsq", "@SindreIvers", "@KevinMidboe", "@OdinBN", "@Hozar132"};
|
||||
char *alphabet[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
|
||||
"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3",
|
||||
"4", "5", "6", "7", "8", "9"};
|
||||
|
||||
byte CoffeeEmpty[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b10001, 0b10001, 0b10001, 0b01110};
|
||||
|
||||
byte CoffeeHank[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b00000,
|
||||
0b11000, 0b01000, 0b11000, 0b00000};
|
||||
|
||||
byte Coffee1[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b10001, 0b10001, 0b11111, 0b01110};
|
||||
|
||||
byte Coffee2[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b10001, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
byte Coffee3[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b11111, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
byte CoffeeSmoke1[8] = {
|
||||
0b00101, 0b01010, 0b00101, 0b11111,
|
||||
0b11111, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
byte CoffeeSmoke2[8] = {
|
||||
0b01010, 0b00101, 0b01010, 0b11111,
|
||||
0b11111, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
|
||||
//byte mac[] = {0x90, 0xA2, 0xDa, 0x0d, 0xA7, 0x51};
|
||||
Twitter twitter("2307428619-jTdwfFJ4r9aYuaYHQ2YeqBWQNOy6nSg6aTRequb");
|
||||
char message[] = "Didn't have anyone to send to... :(";
|
||||
|
||||
const int buttonPin = 9;
|
||||
int buttonState = 0;
|
||||
int animatorSelector = 2;
|
||||
int UD = 1;
|
||||
int LR = 1;
|
||||
|
||||
int i = 1;
|
||||
int j = 0;
|
||||
int k = 0;
|
||||
int lengthMainMenu = 2;
|
||||
int lengthTwitterHandles = 5;
|
||||
int lengthAlphabet = 36;
|
||||
|
||||
boolean boolMainMenu = true;
|
||||
boolean boolTwitterHandles = false;
|
||||
boolean waterBoiling = false;
|
||||
int selected = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
lcd.begin(16, 2);
|
||||
|
||||
pinMode(buttonPin, INPUT);
|
||||
|
||||
//Ethernet.begin(mac);
|
||||
|
||||
lcd.write("Ready!");
|
||||
delay(1000);
|
||||
lcd.clear();
|
||||
|
||||
lcd.createChar(1, CoffeeHank);
|
||||
lcd.createChar(2, CoffeeEmpty);
|
||||
lcd.createChar(3, Coffee1);
|
||||
lcd.createChar(4, Coffee2);
|
||||
lcd.createChar(5, Coffee3);
|
||||
lcd.createChar(6, CoffeeSmoke1);
|
||||
lcd.createChar(7, CoffeeSmoke2);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
while (boolMainMenu == true)
|
||||
{
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
delay(300);
|
||||
if (UD == 1022)
|
||||
{
|
||||
i = 0;
|
||||
lcd.clear();
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(1,1);
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
delay(800);
|
||||
selected = 0;
|
||||
}
|
||||
if (UD == 0)
|
||||
{
|
||||
i = 0;
|
||||
lcd.clear();
|
||||
lcd.setCursor(1, 0);
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
delay(800);
|
||||
selected = 1;
|
||||
}
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
if (LR == 1022)
|
||||
{
|
||||
if (selected == 0)
|
||||
{
|
||||
boolMainMenu = false;
|
||||
boolTwitterHandles = true;
|
||||
i = 0;
|
||||
lcd.clear();
|
||||
lcd.write(">");
|
||||
lcd.write(twitterHandles[i]);
|
||||
lcd.setCursor(1, 1);
|
||||
lcd.write(twitterHandles[i + 1]);
|
||||
}
|
||||
else
|
||||
if (selected == 1)
|
||||
{
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
delay(300);
|
||||
if (UD == 1022)
|
||||
{
|
||||
k++;
|
||||
if (k == 37)
|
||||
{
|
||||
k = 0;
|
||||
}
|
||||
}
|
||||
if (UD == 0)
|
||||
{
|
||||
k--;
|
||||
if (k == -1)
|
||||
{
|
||||
k = 37;
|
||||
}
|
||||
}
|
||||
|
||||
lcd.clear();
|
||||
lcd.write(alphabet[k]);
|
||||
lcd.write(alphabet[k + 1]);
|
||||
|
||||
/*for(int k = 0; k < lengthTwitterHandles; k++)
|
||||
{
|
||||
|
||||
}*/
|
||||
|
||||
if (LR == 0)
|
||||
{
|
||||
//Save the typed-inn name
|
||||
//Add @ to the name
|
||||
lcd.clear();
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(1,1);
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
delay(800);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while(boolTwitterHandles == true)
|
||||
{
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
delay(300);
|
||||
if (UD == 0)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(1,1);
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
delay(800);
|
||||
i++;
|
||||
if (i == lengthMainMenu)
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
if (UD == 1022)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
lcd.setCursor(1,1);
|
||||
lcd.write(mainMenu[i]);
|
||||
delay(800);
|
||||
i--;
|
||||
if (i == 0)
|
||||
{
|
||||
//i = lengthMainMenu;
|
||||
i = 1;
|
||||
}
|
||||
}
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
if (LR == 1022)
|
||||
{
|
||||
//ERROR
|
||||
//Invalid conversion from 'char*' to 'char'
|
||||
//message[] = twitterHandles[i];
|
||||
waterBoiling = false;
|
||||
boolTwitterHandles = false;
|
||||
lcd.clear();
|
||||
}
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
if (LR == 0)
|
||||
{
|
||||
boolTwitterHandles = false;
|
||||
boolMainMenu = true;
|
||||
i = 0;
|
||||
lcd.clear();
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(1, 1);
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
//Maybe (while(waterBoiling == true && buttonState == LOW))
|
||||
while(waterBoiling == true)
|
||||
{
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(animatorSelector);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
animatorSelector++;
|
||||
delay(3000);
|
||||
lcd.clear();
|
||||
|
||||
if(animatorSelector > 5)
|
||||
{
|
||||
animatorSelector = 2;
|
||||
}
|
||||
|
||||
buttonState = digitalRead(buttonPin);
|
||||
if(buttonState == HIGH)
|
||||
{
|
||||
twitter.post(message);
|
||||
waterBoiling = false;
|
||||
buttonState = digitalRead(buttonPin);
|
||||
}
|
||||
}
|
||||
|
||||
while(waterBoiling == false && buttonState == HIGH)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(6 + j);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
j++;
|
||||
delay(1200);
|
||||
if (j == 2)
|
||||
{
|
||||
j = 0;
|
||||
}
|
||||
buttonState = digitalRead(buttonPin);
|
||||
if(buttonState == LOW)
|
||||
{
|
||||
boolMainMenu = true;
|
||||
lcd.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
200
Projects/Tea-duino Main/TeaAnimation/TeaAnimation.ino
Executable file
200
Projects/Tea-duino Main/TeaAnimation/TeaAnimation.ino
Executable file
@@ -0,0 +1,200 @@
|
||||
#include <LiquidCrystal.h>
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <Twitter.h>
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(0, 1, 2, 6, 7, 8);
|
||||
|
||||
byte CoffeeEmpty[8] = {
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b11111,
|
||||
0b10001,
|
||||
0b10001,
|
||||
0b10001,
|
||||
0b01110
|
||||
};
|
||||
|
||||
byte CoffeeHank[8] = {
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b11000,
|
||||
0b01000,
|
||||
0b11000,
|
||||
0b00000
|
||||
};
|
||||
|
||||
byte Coffee1[8] = {
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b11111,
|
||||
0b10001,
|
||||
0b10001,
|
||||
0b11111,
|
||||
0b01110
|
||||
};
|
||||
|
||||
byte Coffee2[8] = {
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b11111,
|
||||
0b10001,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b01110
|
||||
};
|
||||
|
||||
byte Coffee3[8] = {
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b01110
|
||||
};
|
||||
|
||||
byte CoffeeSmoke1[8] = {
|
||||
0b00101,
|
||||
0b01010,
|
||||
0b00101,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b01110
|
||||
};
|
||||
|
||||
byte CoffeeSmoke2[8] = {
|
||||
0b01010,
|
||||
0b00101,
|
||||
0b01010,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b01110
|
||||
};
|
||||
|
||||
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xA7, 0x51 };
|
||||
Twitter twitter("2307428619-jTdwfFJ4r9aYuaYHQ2YeqBWQNOy6nSg6aTRequb");
|
||||
char msg[] = "@KevinMidboe @SindreIvers";
|
||||
|
||||
int buttonPin = 9;
|
||||
|
||||
int animationSelector = 2;
|
||||
int buttonState = 0;
|
||||
|
||||
boolean waterDone = false;
|
||||
boolean tweeted = false;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Ethernet.begin(mac);
|
||||
//Serial.begin(9600);
|
||||
|
||||
lcd.createChar(1, CoffeeHank);
|
||||
lcd.createChar(2, CoffeeEmpty);
|
||||
lcd.createChar(3, Coffee1);
|
||||
lcd.createChar(4, Coffee2);
|
||||
lcd.createChar(5, Coffee3);
|
||||
lcd.createChar(6, CoffeeSmoke1);
|
||||
lcd.createChar(7, CoffeeSmoke2);
|
||||
|
||||
lcd.begin(16, 2);
|
||||
|
||||
pinMode(buttonPin, INPUT);
|
||||
buttonState = LOW;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
while (waterDone == false)
|
||||
{
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(animationSelector);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
animationSelector++;
|
||||
delay(3000);
|
||||
lcd.clear();
|
||||
|
||||
if (animationSelector > 5)
|
||||
{
|
||||
animationSelector = 2;
|
||||
}
|
||||
|
||||
buttonState = digitalRead(buttonPin);
|
||||
if(buttonState == HIGH)
|
||||
{
|
||||
waterDone = true;
|
||||
}
|
||||
}
|
||||
buttonState = digitalRead(buttonPin);
|
||||
if (waterDone == true && buttonState == HIGH)
|
||||
{
|
||||
while(tweeted == false)
|
||||
{
|
||||
Serial.println("connecting ...");
|
||||
if (twitter.post(msg))
|
||||
{
|
||||
// Specify &Serial to output received response to Serial.
|
||||
// If no output is required, you can just omit the argument, e.g.
|
||||
// int status = twitter.wait();
|
||||
int status = twitter.wait(&Serial);
|
||||
if (status == 200)
|
||||
{
|
||||
Serial.println("OK.");
|
||||
tweeted = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("failed : code ");
|
||||
Serial.println(status);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("connection failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
while(buttonState == HIGH && tweeted == true)
|
||||
{
|
||||
delay(1000);
|
||||
lcd.clear();
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(6);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
delay(1200);
|
||||
|
||||
lcd.clear();
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(7);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
delay(1200);
|
||||
|
||||
buttonState = digitalRead(buttonPin);
|
||||
}
|
||||
|
||||
if (buttonState == LOW && tweeted == true)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write(">Choose User");
|
||||
lcd.setCursor(1, 1);
|
||||
lcd.write("Add new User");
|
||||
delay(4000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
284
Projects/Tea-duino Main/Tea_duino/Tea_duino.ino
Executable file
284
Projects/Tea-duino Main/Tea_duino/Tea_duino.ino
Executable file
@@ -0,0 +1,284 @@
|
||||
#include <LiquidCrystal.h>
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <Twitter.h>
|
||||
|
||||
LiquidCrystal lcd(0, 1, 2, 6, 7, 8);
|
||||
|
||||
char *mainMenu[] = {"Choose user", "Add new user"};
|
||||
char *twitterHandles[] = {"@EchoEsq", "@SindreIvers", "@KevinMidboe", "@OdinBN", "@Hozar132"};
|
||||
char *alphabet[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
|
||||
"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3",
|
||||
"4", "5", "6", "7", "8", "9"};
|
||||
|
||||
byte CoffeeEmpty[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b10001, 0b10001, 0b10001, 0b01110};
|
||||
|
||||
byte CoffeeHank[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b00000,
|
||||
0b11000, 0b01000, 0b11000, 0b00000};
|
||||
|
||||
byte Coffee1[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b10001, 0b10001, 0b11111, 0b01110};
|
||||
|
||||
byte Coffee2[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b10001, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
byte Coffee3[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b11111, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
byte CoffeeSmoke1[8] = {
|
||||
0b00101, 0b01010, 0b00101, 0b11111,
|
||||
0b11111, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
byte CoffeeSmoke2[8] = {
|
||||
0b01010, 0b00101, 0b01010, 0b11111,
|
||||
0b11111, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
|
||||
//byte mac[] = {0x90, 0xA2, 0xDa, 0x0d, 0xA7, 0x51};
|
||||
Twitter twitter("2307428619-jTdwfFJ4r9aYuaYHQ2YeqBWQNOy6nSg6aTRequb");
|
||||
char message[] = "Didn't have anyone to send to... :(";
|
||||
|
||||
const int buttonPin = 9;
|
||||
int buttonState = 0;
|
||||
int animatorSelector = 2;
|
||||
int UD = 1;
|
||||
int LR = 1;
|
||||
|
||||
int i = 1;
|
||||
int j = 0;
|
||||
int k = 0;
|
||||
int lengthMainMenu = 2;
|
||||
int lengthTwitterHandles = 5;
|
||||
int lengthAlphabet = 36;
|
||||
|
||||
boolean boolMainMenu = true;
|
||||
boolean boolTwitterHandles = false;
|
||||
boolean waterBoiling = false;
|
||||
int selected = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
lcd.begin(16, 2);
|
||||
|
||||
pinMode(buttonPin, INPUT);
|
||||
|
||||
//Ethernet.begin(mac);
|
||||
|
||||
lcd.write("Ready!");
|
||||
delay(1000);
|
||||
lcd.clear();
|
||||
|
||||
lcd.createChar(1, CoffeeHank);
|
||||
lcd.createChar(2, CoffeeEmpty);
|
||||
lcd.createChar(3, Coffee1);
|
||||
lcd.createChar(4, Coffee2);
|
||||
lcd.createChar(5, Coffee3);
|
||||
lcd.createChar(6, CoffeeSmoke1);
|
||||
lcd.createChar(7, CoffeeSmoke2);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
while (boolMainMenu == true)
|
||||
{
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
delay(300);
|
||||
if (UD == 1022)
|
||||
{
|
||||
i = 0;
|
||||
lcd.clear();
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(1,1);
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
delay(800);
|
||||
selected = 0;
|
||||
}
|
||||
if (UD == 0)
|
||||
{
|
||||
i = 0;
|
||||
lcd.clear();
|
||||
lcd.setCursor(1, 0);
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
delay(800);
|
||||
selected = 1;
|
||||
}
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
if (LR == 1022)
|
||||
{
|
||||
if (selected == 0)
|
||||
{
|
||||
boolMainMenu = false;
|
||||
boolTwitterHandles = true;
|
||||
i = 0;
|
||||
lcd.clear();
|
||||
lcd.write(">");
|
||||
lcd.write(twitterHandles[i]);
|
||||
lcd.setCursor(1, 1);
|
||||
lcd.write(twitterHandles[i + 1]);
|
||||
}
|
||||
else
|
||||
if (selected == 1)
|
||||
{
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
delay(300);
|
||||
if (UD == 1022)
|
||||
{
|
||||
k++;
|
||||
if (k == 37)
|
||||
{
|
||||
k = 0;
|
||||
}
|
||||
}
|
||||
if (UD == 0)
|
||||
{
|
||||
k--;
|
||||
if (k == -1)
|
||||
{
|
||||
k = 37;
|
||||
}
|
||||
}
|
||||
|
||||
lcd.clear();
|
||||
lcd.write(alphabet[k]);
|
||||
lcd.write(alphabet[k + 1]);
|
||||
|
||||
/*for(int k = 0; k < lengthTwitterHandles; k++)
|
||||
{
|
||||
|
||||
}*/
|
||||
|
||||
if (LR == 0)
|
||||
{
|
||||
//Save the typed-inn name
|
||||
//Add @ to the name
|
||||
lcd.clear();
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(1,1);
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
delay(800);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while(boolTwitterHandles == true)
|
||||
{
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
delay(300);
|
||||
if (UD == 0)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(1,1);
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
delay(800);
|
||||
i++;
|
||||
if (i == lengthMainMenu)
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
if (UD == 1022)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
lcd.setCursor(1,1);
|
||||
lcd.write(mainMenu[i]);
|
||||
delay(800);
|
||||
i--;
|
||||
if (i == 0)
|
||||
{
|
||||
//i = lengthMainMenu;
|
||||
i = 1;
|
||||
}
|
||||
}
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
if (LR == 1022)
|
||||
{
|
||||
//ERROR
|
||||
//Invalid conversion from 'char*' to 'char'
|
||||
//message[] = twitterHandles[i];
|
||||
waterBoiling = false;
|
||||
boolTwitterHandles = false;
|
||||
lcd.clear();
|
||||
}
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
if (LR == 0)
|
||||
{
|
||||
boolTwitterHandles = false;
|
||||
boolMainMenu = true;
|
||||
i = 0;
|
||||
lcd.clear();
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(1, 1);
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
//Maybe (while(waterBoiling == true && buttonState == LOW))
|
||||
while(waterBoiling == true)
|
||||
{
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(animatorSelector);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
animatorSelector++;
|
||||
delay(3000);
|
||||
lcd.clear();
|
||||
|
||||
if(animatorSelector > 5)
|
||||
{
|
||||
animatorSelector = 2;
|
||||
}
|
||||
|
||||
buttonState = digitalRead(buttonPin);
|
||||
if(buttonState == HIGH)
|
||||
{
|
||||
twitter.post(message);
|
||||
waterBoiling = false;
|
||||
buttonState = digitalRead(buttonPin);
|
||||
}
|
||||
}
|
||||
|
||||
while(waterBoiling == false && buttonState == HIGH)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(6 + j);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
j++;
|
||||
delay(1200);
|
||||
if (j == 2)
|
||||
{
|
||||
j = 0;
|
||||
}
|
||||
buttonState = digitalRead(buttonPin);
|
||||
if(buttonState == LOW)
|
||||
{
|
||||
boolMainMenu = true;
|
||||
lcd.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
315
Projects/Tea-duino Main/Tea_duino_2_0/Tea_duino_2_0.ino
Executable file
315
Projects/Tea-duino Main/Tea_duino_2_0/Tea_duino_2_0.ino
Executable file
@@ -0,0 +1,315 @@
|
||||
#include <LiquidCrystal.h>
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <Twitter.h>
|
||||
|
||||
LiquidCrystal lcd(0, 1, 2, 6, 7, 8);
|
||||
|
||||
char *menuTree[] = {"mainMenu", "Users", "Add user"};
|
||||
char *mainMenu[] = {"Choose user", "Add user"};
|
||||
char *twitterHandles[] = {"@EchoEsq", "@SindreIvers", "@KevinMidboe", "@Odinbn", "@Hozar132"};
|
||||
char *itsDone[] = {"Vannet er ferdig!", "TEATIME!", "my Man, the water is done!"};
|
||||
|
||||
char *errorWhereIsBoiler [] = {"Sett vannkokeren", "pa knappen."};
|
||||
char *startWaterMessage [] = {"Skru pa vannet!"};
|
||||
|
||||
byte CoffeeEmpty[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b10001, 0b10001, 0b10001, 0b01110};
|
||||
|
||||
byte CoffeeHank[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b00000,
|
||||
0b11000, 0b01000, 0b11000, 0b00000};
|
||||
|
||||
byte Coffee1[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b10001, 0b10001, 0b11111, 0b01110};
|
||||
|
||||
byte Coffee2[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b10001, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
byte Coffee3[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b11111, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
byte CoffeeSmoke1[8] = {
|
||||
0b00101, 0b01010, 0b00101, 0b11111,
|
||||
0b11111, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
byte CoffeeSmoke2[8] = {
|
||||
0b01010, 0b00101, 0b01010, 0b11111,
|
||||
0b11111, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
Twitter twitter("2307428619-TIM5H7Lh6L9HrrQLMynR5cinWpNbiUTt2827myM");
|
||||
byte mac[] = {0x90, 0xA2, 0xDa, 0x0d, 0xA7, 0x51};
|
||||
|
||||
const int buttonPin = 3;
|
||||
int resetPin = 3;
|
||||
int buttonState;
|
||||
int UD = 1;
|
||||
int LR = 1;
|
||||
|
||||
boolean movedDown = false;
|
||||
int upDownCount = 0;
|
||||
int menuSelector = 0;
|
||||
int mainMenuController = 0;
|
||||
int animationSelector = 2;
|
||||
|
||||
char* username;
|
||||
|
||||
int lengthMainMenu = sizeof(mainMenu);
|
||||
int lengthUserMenu = sizeof(twitterHandles);
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(resetPin, OUTPUT);
|
||||
|
||||
lcd.begin(16,2);
|
||||
Ethernet.begin(mac);
|
||||
|
||||
lcd.createChar(1, CoffeeHank);
|
||||
lcd.createChar(2, CoffeeEmpty);
|
||||
lcd.createChar(3, Coffee1);
|
||||
lcd.createChar(4, Coffee2);
|
||||
lcd.createChar(5, Coffee3);
|
||||
lcd.createChar(6, CoffeeSmoke1);
|
||||
lcd.createChar(7, CoffeeSmoke2);
|
||||
|
||||
pinMode(buttonPin, INPUT);
|
||||
|
||||
upDownCount = writeMainMenu(movedDown, upDownCount);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
while (menuTree[menuSelector] == menuTree[0])
|
||||
{
|
||||
delay(200);
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
if (UD == 0)
|
||||
{
|
||||
movedDown = false;
|
||||
upDownCount--;
|
||||
if (upDownCount < 0)
|
||||
{
|
||||
upDownCount = 0;
|
||||
}
|
||||
upDownCount = writeMainMenu(movedDown, upDownCount);
|
||||
}
|
||||
if (UD == 1022)
|
||||
{
|
||||
movedDown = true;
|
||||
upDownCount = writeMainMenu(movedDown, upDownCount);
|
||||
upDownCount++;
|
||||
}
|
||||
if (LR == 0)
|
||||
{
|
||||
menuSelector = 1;
|
||||
upDownCount = 0;
|
||||
upDownCount = writeUserMenu(movedDown, upDownCount);
|
||||
delay(400);
|
||||
}
|
||||
}
|
||||
while (menuTree[menuSelector] == menuTree[1])
|
||||
{
|
||||
delay(200);
|
||||
LR = analogRead(A0);
|
||||
UD = analogRead(A1);
|
||||
if (UD == 0)
|
||||
{
|
||||
movedDown = false;
|
||||
upDownCount--;
|
||||
if (upDownCount < 0)
|
||||
{
|
||||
upDownCount = 0;
|
||||
}
|
||||
upDownCount = writeUserMenu(movedDown, upDownCount);
|
||||
}
|
||||
if (UD == 1022)
|
||||
{
|
||||
movedDown = true;
|
||||
upDownCount = writeUserMenu(movedDown, upDownCount);
|
||||
upDownCount++;
|
||||
}
|
||||
if (LR == 0)
|
||||
{
|
||||
username = twitterHandles[upDownCount];
|
||||
buttonState = analogRead(buttonPin);
|
||||
if (buttonState != 0)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write(errorWhereIsBoiler[0]);
|
||||
lcd.setCursor(0,1);
|
||||
lcd.write(errorWhereIsBoiler[1]);
|
||||
delay(2000);
|
||||
upDownCount = writeUserMenu(movedDown, upDownCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkWaterON(username);
|
||||
}
|
||||
}
|
||||
if (LR == 1022)
|
||||
{
|
||||
menuSelector = 0;
|
||||
upDownCount = 0;
|
||||
upDownCount = writeMainMenu(movedDown, upDownCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int writeMainMenu(boolean movedDown, int upDownCount)
|
||||
{
|
||||
int i = upDownCount;
|
||||
|
||||
lcd.clear();
|
||||
|
||||
if (movedDown == false)
|
||||
{
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(1,1);
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
lcd.setCursor(1,0);
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(0,1);
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int writeUserMenu(boolean movedDown, int upDownCount)
|
||||
{
|
||||
int i = upDownCount;
|
||||
|
||||
lcd.clear();
|
||||
|
||||
if (movedDown == false)
|
||||
{
|
||||
lcd.write(">");
|
||||
lcd.write(twitterHandles[i]);
|
||||
lcd.setCursor(1,1);
|
||||
lcd.write(twitterHandles[i + 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
lcd.setCursor(1,0);
|
||||
lcd.write(twitterHandles[i]);
|
||||
lcd.setCursor(0,1);
|
||||
lcd.write(">");
|
||||
lcd.write(twitterHandles[i + 1]);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void checkWaterON(char* username)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write(startWaterMessage[0]);
|
||||
delay(1500);
|
||||
|
||||
buttonState = analogRead(buttonPin);
|
||||
if (buttonState != 0)
|
||||
{
|
||||
waterOnAndTweet(username);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkWaterON(username);
|
||||
}
|
||||
}
|
||||
|
||||
void waterOnAndTweet(char* username)
|
||||
{
|
||||
buttonState = analogRead(buttonPin);
|
||||
while (buttonState != 0)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.setCursor(6, 1);
|
||||
lcd.write(animationSelector);
|
||||
lcd.setCursor(7, 1);
|
||||
lcd.write(1);
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(animationSelector);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
animationSelector++;
|
||||
delay(1500);
|
||||
if (animationSelector == 6)
|
||||
{
|
||||
animationSelector = 2;
|
||||
}
|
||||
waterOnAndTweet(username);
|
||||
}
|
||||
if (twitter.post(username))
|
||||
{
|
||||
int status = twitter.wait(&lcd);
|
||||
if (status == 200)
|
||||
{
|
||||
waitForPickup();
|
||||
}
|
||||
else
|
||||
if(status == 403)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write("Duplicate tweet!");
|
||||
lcd.setCursor(0,1);
|
||||
lcd.write(status);
|
||||
delay(65000);
|
||||
twitter.post(username);
|
||||
|
||||
// int status = twitter.wait(&lcd);
|
||||
// if(status == 200)
|
||||
// {
|
||||
// waitForPickup();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// waterOnAndTweet(username);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void waitForPickup()
|
||||
{
|
||||
buttonState = analogRead(buttonPin);
|
||||
while (buttonState == 0)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.setCursor(6, 1);
|
||||
lcd.write(6);
|
||||
lcd.setCursor(7, 1);
|
||||
lcd.write(1);
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(6);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
|
||||
delay(1500);
|
||||
lcd.clear();
|
||||
lcd.setCursor(6, 1);
|
||||
lcd.write(7);
|
||||
lcd.setCursor(7, 1);
|
||||
lcd.write(1);
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(7);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
delay(1500);
|
||||
waitForPickup();
|
||||
}
|
||||
while (buttonState != 0)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write("RESET!");
|
||||
digitalWrite(resetPin, HIGH);
|
||||
delay(3000);
|
||||
}
|
||||
}
|
||||
354
Projects/Tea-duino Main/Tea_duino_3_0/Tea_duino_3_0.ino
Executable file
354
Projects/Tea-duino Main/Tea_duino_3_0/Tea_duino_3_0.ino
Executable file
@@ -0,0 +1,354 @@
|
||||
#include <LiquidCrystal.h>
|
||||
#include <JoystickController.h>
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <Twitter.h>
|
||||
|
||||
LiquidCrystal lcd(0, 1, 2, 6, 7, 8);
|
||||
|
||||
char *menuTree[] = {"mainMenu", "Users", "Add user"};
|
||||
char *mainMenu[] = {"Choose user", "Add user"};
|
||||
|
||||
char *twitterHandles[] = {"@KevinMidboe ", "@EchoEsq ", "@SindreIvers ", "@Hozar132 ", "@Odinbn "};
|
||||
char *donePhrases[] = {"Vannet er ferdig! ", "TEATIME ", "my man, the water is done! ", "Kom å hent meg! "};
|
||||
|
||||
char *errorWhereIsBoiler [] = {"Sett vannkokeren", "pa knappen."};
|
||||
char *startWaterMessage [] = {"Skru pa vannet!"};
|
||||
|
||||
byte CoffeeEmpty[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b10001, 0b10001, 0b10001, 0b01110};
|
||||
|
||||
byte CoffeeHank[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b00000,
|
||||
0b11000, 0b01000, 0b11000, 0b00000};
|
||||
|
||||
byte Coffee1[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b10001, 0b10001, 0b11111, 0b01110};
|
||||
|
||||
byte Coffee2[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b10001, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
byte Coffee3[8] = {
|
||||
0b00000, 0b00000, 0b00000, 0b11111,
|
||||
0b11111, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
byte CoffeeSmoke1[8] = {
|
||||
0b00101, 0b01010, 0b00101, 0b11111,
|
||||
0b11111, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
byte CoffeeSmoke2[8] = {
|
||||
0b01010, 0b00101, 0b01010, 0b11111,
|
||||
0b11111, 0b11111, 0b11111, 0b01110};
|
||||
|
||||
Twitter twitter("2307428619-TIM5H7Lh6L9HrrQLMynR5cinWpNbiUTt2827myM");
|
||||
byte mac[] = {0x90, 0xA2, 0xDa, 0x0d, 0xA7, 0x51};
|
||||
|
||||
const int buttonPin = 3;
|
||||
const int resetPin = 3;
|
||||
int buttonState;
|
||||
int UD = 1;
|
||||
int LR = 1;
|
||||
|
||||
boolean movedDown = false;
|
||||
int upDownCount = 0;
|
||||
int menuSelector = 0;
|
||||
int mainMenuController = 0;
|
||||
int animationSelector = 2;
|
||||
|
||||
char* username;
|
||||
|
||||
char buf[100];
|
||||
|
||||
int lengthMainMenu = sizeof(mainMenu);
|
||||
int lengthUserMenu = sizeof(twitterHandles);
|
||||
|
||||
JoystickController controller;
|
||||
|
||||
void setup()
|
||||
{
|
||||
lcd.begin(16,2);
|
||||
Ethernet.begin(mac);
|
||||
|
||||
lcd.createChar(1, CoffeeHank);
|
||||
lcd.createChar(2, CoffeeEmpty);
|
||||
lcd.createChar(3, Coffee1);
|
||||
lcd.createChar(4, Coffee2);
|
||||
lcd.createChar(5, Coffee3);
|
||||
lcd.createChar(6, CoffeeSmoke1);
|
||||
lcd.createChar(7, CoffeeSmoke2);
|
||||
|
||||
pinMode(buttonPin, INPUT);
|
||||
|
||||
upDownCount = writeMainMenu(movedDown, upDownCount);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
while (menuTree[menuSelector] == menuTree[0])
|
||||
{
|
||||
delay(200);
|
||||
controller.update();
|
||||
int direct = controller.getDirection();
|
||||
switch (direct)
|
||||
{
|
||||
case JoystickController::DIRECTION_RIGHT:
|
||||
{
|
||||
movedDown = false;
|
||||
upDownCount--;
|
||||
if (upDownCount < 0)
|
||||
{
|
||||
upDownCount = 0;
|
||||
}
|
||||
upDownCount = writeMainMenu(movedDown, upDownCount);
|
||||
break;
|
||||
}
|
||||
case JoystickController::DIRECTION_LEFT:
|
||||
{
|
||||
movedDown = true;
|
||||
upDownCount = writeMainMenu(movedDown, upDownCount);
|
||||
upDownCount++;
|
||||
break;
|
||||
}
|
||||
case JoystickController::DIRECTION_DOWN:
|
||||
{
|
||||
menuSelector = 1;
|
||||
upDownCount = 0;
|
||||
upDownCount = writeUserMenu(movedDown, upDownCount);
|
||||
delay(400);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (menuTree[menuSelector] == menuTree[1])
|
||||
{
|
||||
delay(200);
|
||||
controller.update();
|
||||
int direct = controller.getDirection();
|
||||
switch (direct)
|
||||
{
|
||||
case JoystickController::DIRECTION_RIGHT:
|
||||
{
|
||||
movedDown = false;
|
||||
upDownCount--;
|
||||
if (upDownCount < 0)
|
||||
{
|
||||
upDownCount = 0;
|
||||
}
|
||||
upDownCount = writeUserMenu(movedDown, upDownCount);
|
||||
break;
|
||||
}
|
||||
case JoystickController::DIRECTION_LEFT:
|
||||
{
|
||||
movedDown = true;
|
||||
upDownCount = writeUserMenu(movedDown, upDownCount);
|
||||
upDownCount++;
|
||||
break;
|
||||
}
|
||||
case JoystickController::DIRECTION_DOWN:
|
||||
{
|
||||
username = twitterHandles[upDownCount];
|
||||
buttonState = analogRead(buttonPin);
|
||||
if (buttonState != 0)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write(errorWhereIsBoiler[0]);
|
||||
lcd.setCursor(0,1);
|
||||
lcd.write(errorWhereIsBoiler[1]);
|
||||
delay(2000);
|
||||
upDownCount = writeUserMenu(movedDown, upDownCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkWaterON(username);
|
||||
}
|
||||
}
|
||||
case JoystickController::DIRECTION_UP :
|
||||
{
|
||||
menuSelector = 0;
|
||||
upDownCount = 0;
|
||||
upDownCount = writeMainMenu(movedDown, upDownCount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int writeMainMenu(boolean movedDown, int upDownCount)
|
||||
{
|
||||
int i = upDownCount;
|
||||
|
||||
lcd.clear();
|
||||
|
||||
if (movedDown == false)
|
||||
{
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(1,1);
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
lcd.setCursor(1,0);
|
||||
lcd.write(mainMenu[i]);
|
||||
lcd.setCursor(0,1);
|
||||
lcd.write(">");
|
||||
lcd.write(mainMenu[i + 1]);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int writeUserMenu(boolean movedDown, int upDownCount)
|
||||
{
|
||||
int i = upDownCount;
|
||||
|
||||
lcd.clear();
|
||||
|
||||
if (movedDown == false)
|
||||
{
|
||||
lcd.write(">");
|
||||
lcd.write(twitterHandles[i]);
|
||||
lcd.setCursor(1,1);
|
||||
lcd.write(twitterHandles[i + 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
lcd.setCursor(1,0);
|
||||
lcd.write(twitterHandles[i]);
|
||||
lcd.setCursor(0,1);
|
||||
lcd.write(">");
|
||||
lcd.write(twitterHandles[i + 1]);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void checkWaterON(char* username)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write(startWaterMessage[0]);
|
||||
delay(1500);
|
||||
|
||||
buttonState = analogRead(buttonPin);
|
||||
if (buttonState != 0)
|
||||
{
|
||||
waterOn(username);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkWaterON(username);
|
||||
}
|
||||
}
|
||||
|
||||
void waterOn(char* username)
|
||||
{
|
||||
buttonState = analogRead(buttonPin);
|
||||
while (buttonState != 0)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.setCursor(6, 1);
|
||||
lcd.write(animationSelector);
|
||||
lcd.setCursor(7, 1);
|
||||
lcd.write(1);
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(animationSelector);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
animationSelector++;
|
||||
delay(1500);
|
||||
if (animationSelector == 6)
|
||||
{
|
||||
animationSelector = 2;
|
||||
}
|
||||
waterOn(username);
|
||||
}
|
||||
tweet(username);
|
||||
}
|
||||
|
||||
void tweet(char* username)
|
||||
{
|
||||
String str(username);
|
||||
randomSeed(analogRead(4));
|
||||
long i = random(4);
|
||||
int j(i);
|
||||
String str2(donePhrases[j]);
|
||||
str += str2;
|
||||
i = random(20);
|
||||
int k(i);
|
||||
str += k;
|
||||
char charBuf[140];
|
||||
str.toCharArray(charBuf, 140);
|
||||
twitter.post(charBuf);
|
||||
/*if ()
|
||||
{
|
||||
int status = twitter.wait(&lcd);
|
||||
if(status == 403)
|
||||
{
|
||||
if (j == 0)
|
||||
{
|
||||
j++;
|
||||
}
|
||||
else
|
||||
if (j == 4)
|
||||
{
|
||||
j--;
|
||||
}
|
||||
else
|
||||
{
|
||||
j++;
|
||||
}
|
||||
String str3(username);
|
||||
String str4(donePhrases[j]);
|
||||
str3 += str4;
|
||||
char charBuf1[140];
|
||||
str3.toCharArray(charBuf1, 140);
|
||||
twitter.post(charBuf1);
|
||||
}
|
||||
}*/
|
||||
|
||||
waitForPickup();
|
||||
}
|
||||
|
||||
void waitForPickup()
|
||||
{
|
||||
buttonState = analogRead(buttonPin);
|
||||
while (buttonState == 0)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.setCursor(6, 1);
|
||||
lcd.write(6);
|
||||
lcd.setCursor(7, 1);
|
||||
lcd.write(1);
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(6);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
|
||||
delay(1500);
|
||||
lcd.clear();
|
||||
lcd.setCursor(6, 1);
|
||||
lcd.write(7);
|
||||
lcd.setCursor(7, 1);
|
||||
lcd.write(1);
|
||||
lcd.setCursor(9, 1);
|
||||
lcd.write(7);
|
||||
lcd.setCursor(10, 1);
|
||||
lcd.write(1);
|
||||
delay(1500);
|
||||
waitForPickup();
|
||||
}
|
||||
if (buttonState != 0)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.write("RESET!");
|
||||
delay(3000);
|
||||
pinMode(resetPin, OUTPUT);
|
||||
digitalWrite(resetPin, HIGH);
|
||||
}
|
||||
56
Projects/Temp Main/TEMP01/TEMP01.ino
Executable file
56
Projects/Temp Main/TEMP01/TEMP01.ino
Executable file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* created by Rui Santos, http://randomnerdtutorials.wordpress.com
|
||||
* Control DC motor with Smartphone via bluetooth
|
||||
* 2013
|
||||
*/
|
||||
int motorPin1 = 3; // pin 2 on L293D IC
|
||||
int motorPin2 = 4; // pin 7 on L293D IC
|
||||
int enablePin = 5; // pin 1 on L293D IC
|
||||
int state;
|
||||
int flag=0; //makes sure that the serial only prints once the state
|
||||
|
||||
void setup() {
|
||||
// sets the pins as outputs:
|
||||
pinMode(motorPin1, OUTPUT);
|
||||
pinMode(motorPin2, OUTPUT);
|
||||
pinMode(enablePin, OUTPUT);
|
||||
// sets enablePin high so that motor can turn on:
|
||||
digitalWrite(enablePin, HIGH);
|
||||
// initialize serial communication at 9600 bits per second:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
//if some date is sent, reads it and saves in state
|
||||
if(Serial.available() > 0){
|
||||
state = Serial.read();
|
||||
flag=0;
|
||||
}
|
||||
// if the state is '0' the DC motor will turn off
|
||||
if (state == '0') {
|
||||
digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
|
||||
digitalWrite(motorPin2, LOW); // set pin 7 on L293D low
|
||||
if(flag == 0){
|
||||
Serial.println("Motor: off");
|
||||
flag=1;
|
||||
}
|
||||
}
|
||||
// if the state is '1' the motor will turn right
|
||||
else if (state == '1') {
|
||||
digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
|
||||
digitalWrite(motorPin2, HIGH); // set pin 7 on L293D high
|
||||
if(flag == 0){
|
||||
Serial.println("Motor: right");
|
||||
flag=1;
|
||||
}
|
||||
}
|
||||
// if the state is '2' the motor will turn left
|
||||
else if (state == '2') {
|
||||
digitalWrite(motorPin1, HIGH); // set pin 2 on L293D high
|
||||
digitalWrite(motorPin2, LOW); // set pin 7 on L293D low
|
||||
if(flag == 0){
|
||||
Serial.println("Motor: left");
|
||||
flag=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
37
Projects/Temp Main/TEMP02/TEMP02.ino
Executable file
37
Projects/Temp Main/TEMP02/TEMP02.ino
Executable file
@@ -0,0 +1,37 @@
|
||||
int latchPin = 12;
|
||||
int clockPin = 11;
|
||||
int dataPin = 13;
|
||||
byte leds = 0;
|
||||
int currentLED = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(latchPin, OUTPUT);
|
||||
pinMode(dataPin, OUTPUT);
|
||||
pinMode(clockPin, OUTPUT);
|
||||
|
||||
leds = 0;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
leds = 0;
|
||||
|
||||
if (currentLED == 7)
|
||||
{
|
||||
currentLED = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentLED++;
|
||||
}
|
||||
|
||||
bitSet(leds, currentLED);
|
||||
|
||||
digitalWrite(latchPin, LOW);
|
||||
delay(250);
|
||||
shiftOut(dataPin, clockPin, LSBFIRST, leds);
|
||||
digitalWrite(latchPin, HIGH);
|
||||
|
||||
delay(250);
|
||||
}
|
||||
114
Projects/Temp Main/Temp_All/Temp_All.ino
Executable file
114
Projects/Temp Main/Temp_All/Temp_All.ino
Executable file
@@ -0,0 +1,114 @@
|
||||
|
||||
int temperaturePin = 0;
|
||||
const int buttonPin = 0;
|
||||
|
||||
int secondDisplayState = HIGH;
|
||||
const boolean ON = HIGH;
|
||||
const boolean OFF = LOW;
|
||||
int buttonState, Avrund;
|
||||
|
||||
int firstDisplay[] = {10, 9, 8, 7, 6, 5, 4};
|
||||
|
||||
int data = 11;
|
||||
int latch = 12;
|
||||
int clock = 13;
|
||||
|
||||
byte firstNumber[10][7] = {
|
||||
{ON, ON, ON, OFF, ON, ON, ON}, // 0
|
||||
{ON, OFF, OFF, OFF, OFF, OFF, ON}, // 1
|
||||
{OFF, ON, ON, ON, OFF, ON, ON}, // 2
|
||||
{ON, ON, OFF, ON, OFF, ON, ON}, // 3
|
||||
{ON, OFF, OFF, ON, ON, OFF, ON}, // 4
|
||||
{ON, ON, OFF, ON, ON, ON, OFF}, // 5
|
||||
{ON, ON, ON, ON, ON, ON, OFF}, // 6
|
||||
{ON, OFF, OFF, OFF, OFF, ON, ON}, // 7
|
||||
{ON, ON, ON, ON, ON, ON, ON}, // 8
|
||||
{ON, ON, OFF, ON, ON, ON, ON}}; // 9
|
||||
|
||||
byte secondNumber[5][7] = {
|
||||
{OFF, ON, ON, ON, ON, ON, ON}, // 0
|
||||
{OFF, OFF, OFF, ON, OFF, OFF, ON}, // 1
|
||||
{ON, ON, ON, OFF, OFF, ON, ON}, // 2
|
||||
{ON, ON, OFF, ON, OFF, ON, ON}, // 3
|
||||
{ON, OFF, OFF, ON, ON, OFF, ON}}; // 4
|
||||
void setup()
|
||||
{
|
||||
pinMode(buttonPin, INPUT);
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
pinMode(firstDisplay[i], OUTPUT);
|
||||
}
|
||||
pinMode(data, OUTPUT);
|
||||
pinMode(clock, OUTPUT);
|
||||
pinMode(latch, OUTPUT);
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
Avrund = 0;
|
||||
buttonState = digitalRead(buttonPin);
|
||||
if (buttonState == LOW)
|
||||
{
|
||||
float temperature = getVoltage(temperaturePin);
|
||||
temperature = (temperature - .5) * 100;
|
||||
|
||||
Serial.print(temperature);
|
||||
Serial.println(" Celsius");
|
||||
|
||||
temperature = temperature * 10;
|
||||
int intConvertedTemp = (int) temperature;
|
||||
String stringConvertedTemp = (String) intConvertedTemp;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (stringConvertedTemp.substring(0,1) == (String) i)
|
||||
{
|
||||
for (int j = 0; j < 7; j++)
|
||||
{
|
||||
changeThe7Segments(j, secondNumber[i][j]);
|
||||
}
|
||||
}
|
||||
if (stringConvertedTemp.substring(2,3) > "5")
|
||||
{
|
||||
Avrund = 1;
|
||||
}
|
||||
if (stringConvertedTemp.substring(1,2) == (String) i)
|
||||
{
|
||||
for (int j = 0; j < 7; j++)
|
||||
{
|
||||
digitalWrite(firstDisplay[j], firstNumber[i + Avrund][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
delay(1250);
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
digitalWrite(firstDisplay[i], OFF);
|
||||
changeThe7Segments(i, OFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
float getVoltage(int pin)
|
||||
{
|
||||
return (analogRead(pin) * .004882814);
|
||||
}
|
||||
void updateSecondDisplay(int value)
|
||||
{
|
||||
digitalWrite(latch, LOW);
|
||||
shiftOut(data, clock, MSBFIRST, value);
|
||||
digitalWrite(latch, HIGH);
|
||||
}
|
||||
int bits[] = {B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000};
|
||||
int masks[] = {B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111};
|
||||
|
||||
void changeThe7Segments(int led, int state)
|
||||
{
|
||||
secondDisplayState = secondDisplayState & masks[led];
|
||||
if(state == ON)
|
||||
{
|
||||
secondDisplayState = secondDisplayState | bits[led];
|
||||
}
|
||||
updateSecondDisplay(secondDisplayState);
|
||||
}
|
||||
46
Projects/Temp Main/Temp_Pre/Temp_Pre.ino
Executable file
46
Projects/Temp Main/Temp_Pre/Temp_Pre.ino
Executable file
@@ -0,0 +1,46 @@
|
||||
/* ---------------------------------------------------------
|
||||
* | Arduino Experimentation Kit Example Code |
|
||||
* | CIRC-10 .: Temperature :. (TMP36 Temperature Sensor) |
|
||||
* ---------------------------------------------------------
|
||||
*
|
||||
* A simple program to output the current temperature to the IDE's debug window
|
||||
*
|
||||
* For more details on this circuit: http://tinyurl.com/c89tvd
|
||||
*/
|
||||
|
||||
//TMP36 Pin Variables
|
||||
int temperaturePin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
|
||||
//the resolution is 10 mV / degree centigrade
|
||||
//(500 mV offset) to make negative temperatures an option
|
||||
|
||||
/*
|
||||
* setup() - this function runs once when you turn your Arduino on
|
||||
* We initialize the serial connection with the computer
|
||||
*/
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600); //Start the serial connection with the copmuter
|
||||
//to view the result open the serial monitor
|
||||
//last button beneath the file bar (looks like a box with an antenae)
|
||||
}
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
float temperature = getVoltage(temperaturePin); //getting the voltage reading from the temperature sensor
|
||||
temperature = (temperature - .5) * 100; //converting from 10 mv per degree with 500 mV offset
|
||||
//to degrees ((volatge - 500mV) times 100)
|
||||
Serial.print(temperature); //printing the result
|
||||
Serial.print(" Celsius ");
|
||||
Serial.print(getVoltage(temperaturePin));
|
||||
Serial.println(" Volt");
|
||||
delay(1000); //waiting a second
|
||||
}
|
||||
|
||||
/*
|
||||
* getVoltage() - returns the voltage on the analog input defined by
|
||||
* pin
|
||||
*/
|
||||
float getVoltage(int pin){
|
||||
return (analogRead(pin) * .004882814); //converting from a 0 to 1023 digital range
|
||||
// to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
|
||||
}
|
||||
59
Projects/Tweet/SimplePost/SimplePost.ino
Executable file
59
Projects/Tweet/SimplePost/SimplePost.ino
Executable file
@@ -0,0 +1,59 @@
|
||||
#include <SPI.h> // needed in Arduino 0019 or later
|
||||
#include <Ethernet.h>
|
||||
#include <Twitter.h>
|
||||
|
||||
// The includion of EthernetDNS is not needed in Arduino IDE 1.0 or later.
|
||||
// Please uncomment below in Arduino IDE 0022 or earlier.
|
||||
//#include <EthernetDNS.h>
|
||||
|
||||
|
||||
// Ethernet Shield Settings
|
||||
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xA7, 0x51 };
|
||||
|
||||
const int buttonPin = 9;
|
||||
int buttonState = 0;
|
||||
|
||||
// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
|
||||
//byte ip[] = { 192, 168, 2, 250 };
|
||||
|
||||
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
|
||||
Twitter twitter("2307428619-jTdwfFJ4r9aYuaYHQ2YeqBWQNOy6nSg6aTRequb");
|
||||
|
||||
// Message to post
|
||||
char msg[] = "@KevinMidboe Vannet er ferdig!";
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
Ethernet.begin(mac);
|
||||
// or you can use DHCP for autoomatic IP address configuration.
|
||||
// Ethernet.begin(mac);
|
||||
Serial.begin(9600);
|
||||
pinMode(buttonPin, INPUT);
|
||||
buttonState = LOW;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
buttonState = digitalRead(buttonPin);
|
||||
if (buttonState == HIGH)
|
||||
{
|
||||
Serial.println("connecting ...");
|
||||
if (twitter.post(msg)) {
|
||||
// Specify &Serial to output received response to Serial.
|
||||
// If no output is required, you can just omit the argument, e.g.
|
||||
// int status = twitter.wait();
|
||||
int status = twitter.wait(&Serial);
|
||||
if (status == 200) {
|
||||
Serial.println("OK.");
|
||||
} else {
|
||||
Serial.print("failed : code ");
|
||||
Serial.println(status);
|
||||
}
|
||||
} else {
|
||||
Serial.println("connection failed.");
|
||||
}
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
55
Projects/Tweet/SimpleTweetPost/SimpleTweetPost.ino
Executable file
55
Projects/Tweet/SimpleTweetPost/SimpleTweetPost.ino
Executable file
@@ -0,0 +1,55 @@
|
||||
#include <SPI.h> // needed in Arduino 0019 or later
|
||||
#include <Ethernet.h>
|
||||
#include <Twitter.h>
|
||||
#include <Time.h>
|
||||
|
||||
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xA7, 0x51 };
|
||||
//byte ip[] = {192, 168, 0, 105};
|
||||
|
||||
char buf[100];
|
||||
|
||||
Twitter twitter("2307428619-TIM5H7Lh6L9HrrQLMynR5cinWpNbiUTt2827myM");
|
||||
|
||||
int i = 0;
|
||||
int buttonPin = 3;
|
||||
|
||||
String stringKevin = String("@KevinMidboe");
|
||||
String stringVannFerdig = String(" Vannet er ferdig! 0");
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
Ethernet.begin(mac);
|
||||
Serial.begin(9600);
|
||||
}
|
||||
/*
|
||||
void tweet(String msg[]) {
|
||||
Serial.println("connecting ...");
|
||||
if (twitter.post(msg)) {
|
||||
int status = twitter.wait(&Serial);
|
||||
if (status == 200) {
|
||||
Serial.println("OK.");
|
||||
} else {
|
||||
Serial.print("failed : code ");
|
||||
Serial.println(status);
|
||||
}
|
||||
} else {
|
||||
Serial.println("connection failed.");
|
||||
}
|
||||
}*/
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (analogRead(buttonPin) != 0)
|
||||
{
|
||||
i++;
|
||||
stringKevin += stringVannFerdig;
|
||||
stringKevin += seconds();
|
||||
char charBuf[50];
|
||||
stringKevin.toCharArray(charBuf, 50);
|
||||
twitter.post(charBuf);
|
||||
|
||||
// zero delay
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
63
Projects/_3DInterface/_3DInterface.ino
Executable file
63
Projects/_3DInterface/_3DInterface.ino
Executable file
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// By Kyle McDonald
|
||||
// From the instructables project at:
|
||||
// http://www.instructables.com/id/DIY-3D-Controller/
|
||||
|
||||
#define resolution 8
|
||||
#define mains 50 // 60: north america, japan; 50: most other places
|
||||
|
||||
#define refresh 2 * 1000000 / mains
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// unused pins are fairly insignificant,
|
||||
// but pulled low to reduce unknown variables
|
||||
for(int i = 2; i < 14; i++) {
|
||||
pinMode(i, OUTPUT);
|
||||
digitalWrite(i, LOW);
|
||||
}
|
||||
|
||||
for(int i = 8; i < 11; i++)
|
||||
pinMode(i, INPUT);
|
||||
|
||||
startTimer();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.print(time(8, B00000001), DEC);
|
||||
Serial.print(" ");
|
||||
Serial.print(time(9, B00000010), DEC);
|
||||
Serial.print(" ");
|
||||
Serial.println(time(10, B00000100), DEC);
|
||||
|
||||
}
|
||||
|
||||
long time(int pin, byte mask) {
|
||||
unsigned long count = 0, total = 0;
|
||||
while(checkTimer() < refresh) {
|
||||
// pinMode is about 6 times slower than assigning
|
||||
// DDRB directly, but that pause is important
|
||||
pinMode(pin, OUTPUT);
|
||||
PORTB = 0;
|
||||
pinMode(pin, INPUT);
|
||||
while((PINB & mask) == 0)
|
||||
count++;
|
||||
total++;
|
||||
}
|
||||
startTimer();
|
||||
return (count << resolution) / total;
|
||||
}
|
||||
|
||||
extern volatile unsigned long timer0_overflow_count;
|
||||
|
||||
void startTimer() {
|
||||
timer0_overflow_count = 0;
|
||||
TCNT0 = 0;
|
||||
}
|
||||
|
||||
unsigned long checkTimer() {
|
||||
return ((timer0_overflow_count << 8) + TCNT0) << 2;
|
||||
}
|
||||
|
||||
|
||||
21
Projects/_5_buttonTest/_5_buttonTest.ino
Normal file
21
Projects/_5_buttonTest/_5_buttonTest.ino
Normal file
@@ -0,0 +1,21 @@
|
||||
const int buttonPin0 = 0;
|
||||
|
||||
const int led = 13;
|
||||
|
||||
void setup() {
|
||||
pinMode(buttonPin0, INPUT);
|
||||
pinMode(led, OUTPUT);
|
||||
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (analogRead(buttonPin0) == 0) {
|
||||
digitalWrite(led, HIGH);
|
||||
}
|
||||
else {
|
||||
digitalWrite(led, LOW);
|
||||
}
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
120
Projects/callbackEcho1/callbackEcho1.ino
Executable file
120
Projects/callbackEcho1/callbackEcho1.ino
Executable file
@@ -0,0 +1,120 @@
|
||||
/*********************************************************************
|
||||
This is an example for our nRF8001 Bluetooth Low Energy Breakout
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/1697
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Kevin Townsend/KTOWN for Adafruit Industries.
|
||||
MIT license, check LICENSE for more information
|
||||
All text above, and the splash screen below must be included in any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
// This version uses call-backs on the event and RX so there's no data handling in the main loop!
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Servo.h>
|
||||
#include "Adafruit_BLE_UART.h"
|
||||
|
||||
#define ADAFRUITBLE_REQ 10
|
||||
#define ADAFRUITBLE_RDY 2
|
||||
#define ADAFRUITBLE_RST 9
|
||||
|
||||
Servo myservo;
|
||||
int pos = 0;
|
||||
|
||||
Adafruit_BLE_UART uart = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
This function is called whenever select ACI events happen
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void aciCallback(aci_evt_opcode_t event)
|
||||
{
|
||||
switch(event)
|
||||
{
|
||||
case ACI_EVT_DEVICE_STARTED:
|
||||
Serial.println(F("Advertising started"));
|
||||
break;
|
||||
case ACI_EVT_CONNECTED:
|
||||
Serial.println(F("Connected!"));
|
||||
break;
|
||||
case ACI_EVT_DISCONNECTED:
|
||||
Serial.println(F("Disconnected or advertising timed out"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
This function is called whenever data arrives on the RX channel
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void rxCallback(uint8_t *buffer, uint8_t len)
|
||||
{
|
||||
Serial.print(F("Received "));
|
||||
Serial.print(len);
|
||||
Serial.print(F(" bytes: "));
|
||||
for(int i=0; i<len; i++)
|
||||
Serial.print((char)buffer[i]);
|
||||
|
||||
char aaa = buffer[0];
|
||||
if (aaa == 't')
|
||||
{
|
||||
myservo.attach(9);
|
||||
if (pos == 0)
|
||||
{
|
||||
pos = 90;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Serial.print(F(" ["));
|
||||
|
||||
for(int i=0; i<len; i++)
|
||||
{
|
||||
Serial.print(" 0x"); Serial.print((char)buffer[i], HEX);
|
||||
}
|
||||
Serial.println(F(" ]"));
|
||||
|
||||
/* Echo the same data back! */
|
||||
uart.write(buffer, len);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
Configure the Arduino and start advertising with the radio
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(9600);
|
||||
while(!Serial); // Leonardo/Micro should wait for serial init
|
||||
Serial.println(F("Adafruit Bluefruit Low Energy nRF8001 Callback Echo demo"));
|
||||
|
||||
uart.setRXcallback(rxCallback);
|
||||
uart.setACIcallback(aciCallback);
|
||||
// uart.setDeviceName("NEWNAME"); /* 7 characters max! */
|
||||
uart.begin();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
Constantly checks for new events on the nRF8001
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void loop()
|
||||
{
|
||||
uart.pollACI();
|
||||
}
|
||||
105
Projects/codeDebouncePushButtonOnOff/codeDebouncePushButtonOnOff.ino
Executable file
105
Projects/codeDebouncePushButtonOnOff/codeDebouncePushButtonOnOff.ino
Executable file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
Debounce
|
||||
|
||||
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
|
||||
press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
|
||||
a minimum delay between toggles to debounce the circuit (i.e. to ignore
|
||||
noise).
|
||||
|
||||
The circuit:
|
||||
* LED attached from pin 13 to ground
|
||||
* pushbutton attached from pin 2 to +5V
|
||||
* 10K resistor attached from pin 2 to ground
|
||||
|
||||
* Note: On most Arduino boards, there is already an LED on the board
|
||||
connected to pin 13, so you don't need any extra components for this example.
|
||||
|
||||
|
||||
created 21 November 2006
|
||||
by David A. Mellis
|
||||
modified 3 Jul 2009
|
||||
by Limor Fried
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Debounce
|
||||
*/
|
||||
|
||||
// constants won't change. They're used here to
|
||||
// set pin numbers:
|
||||
const int buttonPin = 0; // the number of the pushbutton pin
|
||||
const int ledPin1 = 4; // the number of the LED pin
|
||||
const int ledPin2 = 5;
|
||||
const int ledPin3 = 6;
|
||||
const int ledPin4 = 7;
|
||||
const int ledPin5 = 8;
|
||||
const int ledPin6 = 9;
|
||||
const int ledPin7 = 10;
|
||||
|
||||
// Variables will change:
|
||||
int ledState = HIGH; // the current state of the output pin
|
||||
int buttonState; // the current reading from the input pin
|
||||
int lastButtonState = LOW; // the previous reading from the input pin
|
||||
|
||||
// the following variables are long's because the time, measured in miliseconds,
|
||||
// will quickly become a bigger number than can be stored in an int.
|
||||
long lastDebounceTime = 0; // the last time the output pin was toggled
|
||||
long debounceDelay = 50; // the debounce time; increase if the output flickers
|
||||
|
||||
void setup() {
|
||||
pinMode(buttonPin, INPUT);
|
||||
pinMode(ledPin1, OUTPUT);
|
||||
pinMode(ledPin2, OUTPUT);
|
||||
pinMode(ledPin3, OUTPUT);
|
||||
pinMode(ledPin4, OUTPUT);
|
||||
pinMode(ledPin5, OUTPUT);
|
||||
pinMode(ledPin6, OUTPUT);
|
||||
pinMode(ledPin7, OUTPUT);
|
||||
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the state of the switch into a local variable:
|
||||
int reading = digitalRead(buttonPin);
|
||||
|
||||
|
||||
|
||||
// check to see if you just pressed the button
|
||||
// (i.e. the input went from LOW to HIGH), and you've waited
|
||||
// long enough since the last press to ignore any noise:
|
||||
|
||||
// If the switch changed, due to noise or pressing:
|
||||
if (reading != lastButtonState) {
|
||||
// reset the debouncing timer
|
||||
lastDebounceTime = millis();
|
||||
|
||||
// this is all that's new to the code
|
||||
// toggles the ledState variable each time the button is pressed
|
||||
if (buttonState == HIGH) {
|
||||
ledState =!ledState;
|
||||
Serial.println(ledState);
|
||||
}
|
||||
}
|
||||
|
||||
if ((millis() - lastDebounceTime) > debounceDelay) {
|
||||
// whatever the reading is at, it's been there for longer
|
||||
// than the debounce delay, so take it as the actual current state:
|
||||
buttonState = reading;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// set the LED using the state of the button:
|
||||
digitalWrite(ledPin1, ledState);
|
||||
digitalWrite(ledPin2, ledState);
|
||||
digitalWrite(ledPin3, ledState);
|
||||
digitalWrite(ledPin4, ledState);
|
||||
digitalWrite(ledPin5, ledState);
|
||||
digitalWrite(ledPin6, ledState);
|
||||
digitalWrite(ledPin7, ledState);
|
||||
|
||||
// save the reading. Next time through the loop,
|
||||
// it'll be the lastButtonState:
|
||||
lastButtonState = reading;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
// The serial connection to the GPS module
|
||||
SoftwareSerial gpsSerial(4, 3);
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
gpsSerial.begin(9600);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
while (gpsSerial.available()) { // check for gps data
|
||||
Serial.write(gpsSerial.read());
|
||||
}
|
||||
}
|
||||
2
Projects/libraries/Installed_libs/Adafruit_BLEFirmata/.gitignore
vendored
Executable file
2
Projects/libraries/Installed_libs/Adafruit_BLEFirmata/.gitignore
vendored
Executable file
@@ -0,0 +1,2 @@
|
||||
.DS_Store
|
||||
release.sh
|
||||
463
Projects/libraries/Installed_libs/Adafruit_BLEFirmata/Adafruit_BLE_Firmata.cpp
Executable file
463
Projects/libraries/Installed_libs/Adafruit_BLEFirmata/Adafruit_BLE_Firmata.cpp
Executable file
@@ -0,0 +1,463 @@
|
||||
/*
|
||||
Firmata.cpp - Firmata library
|
||||
Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved.
|
||||
|
||||
Modified for Adafruit_BLE_Uart by Limor Fried/Kevin Townsend for
|
||||
Adafruit Industries, 2014
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
See file LICENSE.txt for further informations on licensing terms.
|
||||
*/
|
||||
|
||||
//******************************************************************************
|
||||
//* Includes
|
||||
//******************************************************************************
|
||||
|
||||
#include "Adafruit_BLE_Firmata.h"
|
||||
|
||||
extern "C" {
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
//* Support Functions
|
||||
//******************************************************************************
|
||||
|
||||
void Adafruit_BLE_FirmataClass::sendValueAsTwo7bitBytes(int value)
|
||||
{
|
||||
FirmataSerial.write(value & B01111111); // LSB
|
||||
FirmataSerial.write(value >> 7 & B01111111); // MSB
|
||||
}
|
||||
|
||||
void Adafruit_BLE_FirmataClass::startSysex(void)
|
||||
{
|
||||
FirmataSerial.write(START_SYSEX);
|
||||
}
|
||||
|
||||
void Adafruit_BLE_FirmataClass::endSysex(void)
|
||||
{
|
||||
FirmataSerial.write(END_SYSEX);
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
//* Constructors
|
||||
//******************************************************************************
|
||||
|
||||
Adafruit_BLE_FirmataClass::Adafruit_BLE_FirmataClass(Adafruit_BLE_UART &s) : FirmataSerial(s)
|
||||
{
|
||||
firmwareVersionCount = 0;
|
||||
systemReset();
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
//* Public Methods
|
||||
//******************************************************************************
|
||||
|
||||
/* begin method for overriding default serial bitrate */
|
||||
void Adafruit_BLE_FirmataClass::begin(void)
|
||||
{
|
||||
blinkVersion();
|
||||
printVersion();
|
||||
printFirmwareVersion();
|
||||
}
|
||||
|
||||
void Adafruit_BLE_FirmataClass::begin(Adafruit_BLE_UART &s)
|
||||
{
|
||||
FirmataSerial = s;
|
||||
systemReset();
|
||||
printVersion();
|
||||
printFirmwareVersion();
|
||||
}
|
||||
|
||||
// output the protocol version message to the serial port
|
||||
void Adafruit_BLE_FirmataClass::printVersion(void) {
|
||||
FirmataSerial.write(REPORT_VERSION);
|
||||
FirmataSerial.write(FIRMATA_MAJOR_VERSION);
|
||||
FirmataSerial.write(FIRMATA_MINOR_VERSION);
|
||||
}
|
||||
|
||||
void Adafruit_BLE_FirmataClass::blinkVersion(void)
|
||||
{
|
||||
// flash the pin with the protocol version
|
||||
pinMode(VERSION_BLINK_PIN,OUTPUT);
|
||||
pin13strobe(FIRMATA_MAJOR_VERSION, 40, 210);
|
||||
delay(250);
|
||||
pin13strobe(FIRMATA_MINOR_VERSION, 40, 210);
|
||||
delay(125);
|
||||
}
|
||||
|
||||
void Adafruit_BLE_FirmataClass::printFirmwareVersion(void)
|
||||
{
|
||||
byte i;
|
||||
|
||||
if(firmwareVersionCount) { // make sure that the name has been set before reporting
|
||||
startSysex();
|
||||
FirmataSerial.write(REPORT_FIRMWARE);
|
||||
FirmataSerial.write(firmwareVersionVector[0]); // major version number
|
||||
FirmataSerial.write(firmwareVersionVector[1]); // minor version number
|
||||
for(i=2; i<firmwareVersionCount; ++i) {
|
||||
sendValueAsTwo7bitBytes(firmwareVersionVector[i]);
|
||||
}
|
||||
endSysex();
|
||||
}
|
||||
}
|
||||
|
||||
void Adafruit_BLE_FirmataClass::setFirmwareNameAndVersion(const char *name, byte major, byte minor)
|
||||
{
|
||||
const char *filename;
|
||||
char *extension;
|
||||
|
||||
// parse out ".cpp" and "applet/" that comes from using __FILE__
|
||||
extension = strstr(name, ".cpp");
|
||||
filename = strrchr(name, '/') + 1; //points to slash, +1 gets to start of filename
|
||||
// add two bytes for version numbers
|
||||
if(extension && filename) {
|
||||
firmwareVersionCount = extension - filename + 2;
|
||||
} else {
|
||||
firmwareVersionCount = strlen(name) + 2;
|
||||
filename = name;
|
||||
}
|
||||
firmwareVersionVector = (byte *) malloc(firmwareVersionCount);
|
||||
firmwareVersionVector[firmwareVersionCount] = 0;
|
||||
firmwareVersionVector[0] = major;
|
||||
firmwareVersionVector[1] = minor;
|
||||
strncpy((char*)firmwareVersionVector + 2, filename, firmwareVersionCount - 2);
|
||||
// alas, no snprintf on Arduino
|
||||
// snprintf(firmwareVersionVector, MAX_DATA_BYTES, "%c%c%s",
|
||||
// (char)major, (char)minor, firmwareVersionVector);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Serial Receive Handling
|
||||
|
||||
int Adafruit_BLE_FirmataClass::available(void)
|
||||
{
|
||||
return FirmataSerial.available();
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_BLE_FirmataClass::processSysexMessage(void)
|
||||
{
|
||||
switch(storedInputData[0]) { //first byte in buffer is command
|
||||
case REPORT_FIRMWARE:
|
||||
printFirmwareVersion();
|
||||
break;
|
||||
case STRING_DATA:
|
||||
if(currentStringCallback) {
|
||||
byte bufferLength = (sysexBytesRead - 1) / 2;
|
||||
char *buffer = (char*)malloc(bufferLength * sizeof(char));
|
||||
byte i = 1;
|
||||
byte j = 0;
|
||||
while(j < bufferLength) {
|
||||
buffer[j] = (char)storedInputData[i];
|
||||
i++;
|
||||
buffer[j] += (char)(storedInputData[i] << 7);
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
(*currentStringCallback)(buffer);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if(currentSysexCallback)
|
||||
(*currentSysexCallback)(storedInputData[0], sysexBytesRead - 1, storedInputData + 1);
|
||||
}
|
||||
}
|
||||
|
||||
int Adafruit_BLE_FirmataClass::processInput(void)
|
||||
{
|
||||
int inputData = FirmataSerial.read(); // this is 'int' to handle -1 when no data
|
||||
int command;
|
||||
|
||||
if (inputData == -1) return -1;
|
||||
|
||||
if (parsingSysex) {
|
||||
if(inputData == END_SYSEX) {
|
||||
//stop sysex byte
|
||||
parsingSysex = false;
|
||||
//fire off handler function
|
||||
processSysexMessage();
|
||||
} else {
|
||||
//normal data byte - add to buffer
|
||||
storedInputData[sysexBytesRead] = inputData;
|
||||
sysexBytesRead++;
|
||||
}
|
||||
} else if( (waitForData > 0) && (inputData < 128) ) {
|
||||
waitForData--;
|
||||
storedInputData[waitForData] = inputData;
|
||||
#ifdef BLE_DEBUG
|
||||
Serial.print(F(" 0x")); Serial.print(inputData, HEX);
|
||||
#endif
|
||||
|
||||
if( (waitForData==0) && executeMultiByteCommand ) { // got the whole message
|
||||
|
||||
#ifdef BLE_DEBUG
|
||||
Serial.println();
|
||||
#endif
|
||||
|
||||
|
||||
switch(executeMultiByteCommand) {
|
||||
case ANALOG_MESSAGE:
|
||||
if(currentAnalogCallback) {
|
||||
(*currentAnalogCallback)(multiByteChannel,
|
||||
(storedInputData[0] << 7)
|
||||
+ storedInputData[1]);
|
||||
}
|
||||
break;
|
||||
case DIGITAL_MESSAGE:
|
||||
if(currentDigitalCallback) {
|
||||
(*currentDigitalCallback)(multiByteChannel,
|
||||
(storedInputData[0] << 7)
|
||||
+ storedInputData[1]);
|
||||
}
|
||||
break;
|
||||
case SET_PIN_MODE:
|
||||
if(currentPinModeCallback)
|
||||
(*currentPinModeCallback)(storedInputData[1], storedInputData[0]);
|
||||
break;
|
||||
case REPORT_ANALOG:
|
||||
if(currentReportAnalogCallback)
|
||||
(*currentReportAnalogCallback)(multiByteChannel,storedInputData[0]);
|
||||
break;
|
||||
case REPORT_DIGITAL:
|
||||
if(currentReportDigitalCallback)
|
||||
(*currentReportDigitalCallback)(multiByteChannel,storedInputData[0]);
|
||||
break;
|
||||
}
|
||||
executeMultiByteCommand = 0;
|
||||
}
|
||||
} else {
|
||||
#ifdef BLE_DEBUG
|
||||
Serial.print(F("\tReceived 0x")); Serial.print(inputData, HEX);
|
||||
#endif
|
||||
// remove channel info from command byte if less than 0xF0
|
||||
if(inputData < 0xF0) {
|
||||
command = inputData & 0xF0;
|
||||
multiByteChannel = inputData & 0x0F;
|
||||
} else {
|
||||
command = inputData;
|
||||
// commands in the 0xF* range don't use channel data
|
||||
}
|
||||
switch (command) {
|
||||
case ANALOG_MESSAGE:
|
||||
case DIGITAL_MESSAGE:
|
||||
case SET_PIN_MODE:
|
||||
waitForData = 2; // two data bytes needed
|
||||
executeMultiByteCommand = command;
|
||||
break;
|
||||
case REPORT_ANALOG:
|
||||
case REPORT_DIGITAL:
|
||||
waitForData = 1; // two data bytes needed
|
||||
executeMultiByteCommand = command;
|
||||
break;
|
||||
case START_SYSEX:
|
||||
parsingSysex = true;
|
||||
sysexBytesRead = 0;
|
||||
break;
|
||||
case SYSTEM_RESET:
|
||||
systemReset();
|
||||
break;
|
||||
case REPORT_VERSION:
|
||||
printVersion();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return inputData;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Serial Send Handling
|
||||
|
||||
// send an analog message
|
||||
void Adafruit_BLE_FirmataClass::sendAnalog(byte pin, int value)
|
||||
{
|
||||
// create a three byte buffer
|
||||
uint8_t sendbuffer[3];
|
||||
|
||||
// pin can only be 0-15, so chop higher bits
|
||||
//FirmataSerial.write(ANALOG_MESSAGE | (pin & 0xF));
|
||||
sendbuffer[0] = ANALOG_MESSAGE | (pin & 0xF);
|
||||
|
||||
//sendValueAsTwo7bitBytes(value);
|
||||
sendbuffer[1] = value % 128; // Tx bits 0-6
|
||||
sendbuffer[2] = (value >> 7) &0x7F; // Tx bits 7-13
|
||||
|
||||
FirmataSerial.write(sendbuffer, 3);
|
||||
}
|
||||
|
||||
// send a single digital pin in a digital message
|
||||
void Adafruit_BLE_FirmataClass::sendDigital(byte pin, int value)
|
||||
{
|
||||
/* TODO add single pin digital messages to the protocol, this needs to
|
||||
* track the last digital data sent so that it can be sure to change just
|
||||
* one bit in the packet. This is complicated by the fact that the
|
||||
* numbering of the pins will probably differ on Arduino, Wiring, and
|
||||
* other boards. The DIGITAL_MESSAGE sends 14 bits at a time, but it is
|
||||
* probably easier to send 8 bit ports for any board with more than 14
|
||||
* digital pins.
|
||||
*/
|
||||
|
||||
// TODO: the digital message should not be sent on the serial port every
|
||||
// time sendDigital() is called. Instead, it should add it to an int
|
||||
// which will be sent on a schedule. If a pin changes more than once
|
||||
// before the digital message is sent on the serial port, it should send a
|
||||
// digital message for each change.
|
||||
|
||||
// if(value == 0)
|
||||
// sendDigitalPortPair();
|
||||
}
|
||||
|
||||
|
||||
// send 14-bits in a single digital message (protocol v1)
|
||||
// send an 8-bit port in a single digital message (protocol v2)
|
||||
void Adafruit_BLE_FirmataClass::sendDigitalPort(byte portNumber, int portData)
|
||||
{
|
||||
// create a three byte buffer
|
||||
uint8_t sendbuffer[3];
|
||||
|
||||
sendbuffer[0] = DIGITAL_MESSAGE | (portNumber & 0xF);
|
||||
sendbuffer[1] = (byte)portData % 128; // Tx bits 0-6
|
||||
sendbuffer[2] = portData >> 7; // Tx bits 7-13
|
||||
FirmataSerial.write(sendbuffer, 3);
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_BLE_FirmataClass::sendSysex(byte command, byte bytec, byte* bytev)
|
||||
{
|
||||
byte i;
|
||||
startSysex();
|
||||
FirmataSerial.write(command);
|
||||
for(i=0; i<bytec; i++) {
|
||||
sendValueAsTwo7bitBytes(bytev[i]);
|
||||
}
|
||||
endSysex();
|
||||
}
|
||||
|
||||
void Adafruit_BLE_FirmataClass::sendString(byte command, const char* string)
|
||||
{
|
||||
sendSysex(command, strlen(string), (byte *)string);
|
||||
}
|
||||
|
||||
|
||||
// send a string as the protocol string type
|
||||
void Adafruit_BLE_FirmataClass::sendString(const char* string)
|
||||
{
|
||||
sendString(STRING_DATA, string);
|
||||
}
|
||||
|
||||
|
||||
// Internal Actions/////////////////////////////////////////////////////////////
|
||||
|
||||
// generic callbacks
|
||||
void Adafruit_BLE_FirmataClass::attach(byte command, callbackFunction newFunction)
|
||||
{
|
||||
switch(command) {
|
||||
case ANALOG_MESSAGE: currentAnalogCallback = newFunction; break;
|
||||
case DIGITAL_MESSAGE: currentDigitalCallback = newFunction; break;
|
||||
case REPORT_ANALOG: currentReportAnalogCallback = newFunction; break;
|
||||
case REPORT_DIGITAL: currentReportDigitalCallback = newFunction; break;
|
||||
case SET_PIN_MODE: currentPinModeCallback = newFunction; break;
|
||||
}
|
||||
}
|
||||
|
||||
void Adafruit_BLE_FirmataClass::attach(byte command, systemResetCallbackFunction newFunction)
|
||||
{
|
||||
switch(command) {
|
||||
case SYSTEM_RESET: currentSystemResetCallback = newFunction; break;
|
||||
}
|
||||
}
|
||||
|
||||
void Adafruit_BLE_FirmataClass::attach(byte command, stringCallbackFunction newFunction)
|
||||
{
|
||||
switch(command) {
|
||||
case STRING_DATA: currentStringCallback = newFunction; break;
|
||||
}
|
||||
}
|
||||
|
||||
void Adafruit_BLE_FirmataClass::attach(byte command, sysexCallbackFunction newFunction)
|
||||
{
|
||||
currentSysexCallback = newFunction;
|
||||
}
|
||||
|
||||
void Adafruit_BLE_FirmataClass::detach(byte command)
|
||||
{
|
||||
switch(command) {
|
||||
case SYSTEM_RESET: currentSystemResetCallback = NULL; break;
|
||||
case STRING_DATA: currentStringCallback = NULL; break;
|
||||
case START_SYSEX: currentSysexCallback = NULL; break;
|
||||
default:
|
||||
attach(command, (callbackFunction)NULL);
|
||||
}
|
||||
}
|
||||
|
||||
// sysex callbacks
|
||||
/*
|
||||
* this is too complicated for analogReceive, but maybe for Sysex?
|
||||
void Adafruit_BLE_FirmataClass::attachSysex(sysexFunction newFunction)
|
||||
{
|
||||
byte i;
|
||||
byte tmpCount = analogReceiveFunctionCount;
|
||||
analogReceiveFunction* tmpArray = analogReceiveFunctionArray;
|
||||
analogReceiveFunctionCount++;
|
||||
analogReceiveFunctionArray = (analogReceiveFunction*) calloc(analogReceiveFunctionCount, sizeof(analogReceiveFunction));
|
||||
for(i = 0; i < tmpCount; i++) {
|
||||
analogReceiveFunctionArray[i] = tmpArray[i];
|
||||
}
|
||||
analogReceiveFunctionArray[tmpCount] = newFunction;
|
||||
free(tmpArray);
|
||||
}
|
||||
*/
|
||||
|
||||
//******************************************************************************
|
||||
//* Private Methods
|
||||
//******************************************************************************/
|
||||
|
||||
|
||||
// resets the system state upon a SYSTEM_RESET message from the host software
|
||||
void Adafruit_BLE_FirmataClass::systemReset(void)
|
||||
{
|
||||
byte i;
|
||||
|
||||
waitForData = 0; // this flag says the next serial input will be data
|
||||
executeMultiByteCommand = 0; // execute this after getting multi-byte data
|
||||
multiByteChannel = 0; // channel data for multiByteCommands
|
||||
|
||||
|
||||
for(i=0; i<MAX_DATA_BYTES; i++) {
|
||||
storedInputData[i] = 0;
|
||||
}
|
||||
|
||||
parsingSysex = false;
|
||||
sysexBytesRead = 0;
|
||||
|
||||
if(currentSystemResetCallback)
|
||||
(*currentSystemResetCallback)();
|
||||
|
||||
//flush(); //TODO uncomment when Firmata is a subclass of HardwareSerial
|
||||
}
|
||||
|
||||
|
||||
|
||||
// =============================================================================
|
||||
// used for flashing the pin for the version number
|
||||
void Adafruit_BLE_FirmataClass::pin13strobe(int count, int onInterval, int offInterval)
|
||||
{
|
||||
byte i;
|
||||
pinMode(VERSION_BLINK_PIN, OUTPUT);
|
||||
for(i=0; i<count; i++) {
|
||||
delay(offInterval);
|
||||
digitalWrite(VERSION_BLINK_PIN, HIGH);
|
||||
delay(onInterval);
|
||||
digitalWrite(VERSION_BLINK_PIN, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
182
Projects/libraries/Installed_libs/Adafruit_BLEFirmata/Adafruit_BLE_Firmata.h
Executable file
182
Projects/libraries/Installed_libs/Adafruit_BLEFirmata/Adafruit_BLE_Firmata.h
Executable file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
Firmata.h - Firmata library
|
||||
Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved.
|
||||
|
||||
Modified for Adafruit_BLE_Uart by Limor Fried/Kevin Townsend for
|
||||
Adafruit Industries, 2014
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
See file LICENSE.txt for further informations on licensing terms.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef Adafruit_BLE_Firmata_h
|
||||
#define Adafruit_BLE_Firmata_h
|
||||
|
||||
#include "Adafruit_BLE_UART.h"
|
||||
#include "Boards.h" /* Hardware Abstraction Layer + Wiring/Arduino */
|
||||
|
||||
#define BLE_DEBUG
|
||||
|
||||
// move the following defines to Firmata.h?
|
||||
#define I2C_WRITE B00000000
|
||||
#define I2C_READ B00001000
|
||||
#define I2C_READ_CONTINUOUSLY B00010000
|
||||
#define I2C_STOP_READING B00011000
|
||||
#define I2C_READ_WRITE_MODE_MASK B00011000
|
||||
#define I2C_10BIT_ADDRESS_MODE_MASK B00100000
|
||||
|
||||
#define MAX_QUERIES 8
|
||||
#define MINIMUM_SAMPLING_INTERVAL 10
|
||||
|
||||
#define REGISTER_NOT_SPECIFIED -1
|
||||
|
||||
/* Version numbers for the protocol. The protocol is still changing, so these
|
||||
* version numbers are important. This number can be queried so that host
|
||||
* software can test whether it will be compatible with the currently
|
||||
* installed firmware. */
|
||||
#define FIRMATA_MAJOR_VERSION 2 // for non-compatible changes
|
||||
#define FIRMATA_MINOR_VERSION 3 // for backwards compatible changes
|
||||
#define FIRMATA_BUGFIX_VERSION 1 // for bugfix releases
|
||||
|
||||
#define MAX_DATA_BYTES 32 // max number of data bytes in non-Sysex messages
|
||||
|
||||
// message command bytes (128-255/0x80-0xFF)
|
||||
#define DIGITAL_MESSAGE 0x90 // send data for a digital pin
|
||||
#define ANALOG_MESSAGE 0xE0 // send data for an analog pin (or PWM)
|
||||
#define REPORT_ANALOG 0xC0 // enable analog input by pin #
|
||||
#define REPORT_DIGITAL 0xD0 // enable digital input by port pair
|
||||
//
|
||||
#define SET_PIN_MODE 0xF4 // set a pin to INPUT/OUTPUT/PWM/etc
|
||||
//
|
||||
#define REPORT_VERSION 0xF9 // report protocol version
|
||||
#define SYSTEM_RESET 0xFF // reset from MIDI
|
||||
//
|
||||
#define START_SYSEX 0xF0 // start a MIDI Sysex message
|
||||
#define END_SYSEX 0xF7 // end a MIDI Sysex message
|
||||
|
||||
// extended command set using sysex (0-127/0x00-0x7F)
|
||||
/* 0x00-0x0F reserved for user-defined commands */
|
||||
#define SERVO_CONFIG 0x70 // set max angle, minPulse, maxPulse, freq
|
||||
#define STRING_DATA 0x71 // a string message with 14-bits per char
|
||||
#define SHIFT_DATA 0x75 // a bitstream to/from a shift register
|
||||
#define I2C_REQUEST 0x76 // send an I2C read/write request
|
||||
#define I2C_REPLY 0x77 // a reply to an I2C read request
|
||||
#define I2C_CONFIG 0x78 // config I2C settings such as delay times and power pins
|
||||
#define EXTENDED_ANALOG 0x6F // analog write (PWM, Servo, etc) to any pin
|
||||
#define PIN_STATE_QUERY 0x6D // ask for a pin's current mode and value
|
||||
#define PIN_STATE_RESPONSE 0x6E // reply with pin's current mode and value
|
||||
#define CAPABILITY_QUERY 0x6B // ask for supported modes and resolution of all pins
|
||||
#define CAPABILITY_RESPONSE 0x6C // reply with supported modes and resolution
|
||||
#define ANALOG_MAPPING_QUERY 0x69 // ask for mapping of analog to pin numbers
|
||||
#define ANALOG_MAPPING_RESPONSE 0x6A // reply with mapping info
|
||||
#define REPORT_FIRMWARE 0x79 // report name and version of the firmware
|
||||
#define SAMPLING_INTERVAL 0x7A // set the poll rate of the main loop
|
||||
#define SYSEX_NON_REALTIME 0x7E // MIDI Reserved for non-realtime messages
|
||||
#define SYSEX_REALTIME 0x7F // MIDI Reserved for realtime messages
|
||||
// these are DEPRECATED to make the naming more consistent
|
||||
#define FIRMATA_STRING 0x71 // same as STRING_DATA
|
||||
#define SYSEX_I2C_REQUEST 0x76 // same as I2C_REQUEST
|
||||
#define SYSEX_I2C_REPLY 0x77 // same as I2C_REPLY
|
||||
#define SYSEX_SAMPLING_INTERVAL 0x7A // same as SAMPLING_INTERVAL
|
||||
|
||||
// pin modes
|
||||
//#define INPUT 0x00 // defined in wiring.h
|
||||
//#define OUTPUT 0x01 // defined in wiring.h
|
||||
#define ANALOG 0x02 // analog pin in analogInput mode
|
||||
#define PWM 0x03 // digital pin in PWM output mode
|
||||
#define SERVO 0x04 // digital pin in Servo output mode
|
||||
#define SHIFT 0x05 // shiftIn/shiftOut mode
|
||||
#define I2C 0x06 // pin included in I2C setup
|
||||
#define TOTAL_PIN_MODES 7
|
||||
|
||||
extern "C" {
|
||||
// callback function types
|
||||
typedef void (*callbackFunction)(byte, int);
|
||||
typedef void (*systemResetCallbackFunction)(void);
|
||||
typedef void (*stringCallbackFunction)(char*);
|
||||
typedef void (*sysexCallbackFunction)(byte command, byte argc, byte*argv);
|
||||
}
|
||||
|
||||
|
||||
// TODO make it a subclass of a generic Serial/Stream base class
|
||||
class Adafruit_BLE_FirmataClass
|
||||
{
|
||||
public:
|
||||
Adafruit_BLE_FirmataClass(Adafruit_BLE_UART &s);
|
||||
/* Arduino constructors */
|
||||
void begin();
|
||||
void begin(Adafruit_BLE_UART &s);
|
||||
/* querying functions */
|
||||
void printVersion(void);
|
||||
void blinkVersion(void);
|
||||
void printFirmwareVersion(void);
|
||||
//void setFirmwareVersion(byte major, byte minor); // see macro below
|
||||
void setFirmwareNameAndVersion(const char *name, byte major, byte minor);
|
||||
/* serial receive handling */
|
||||
int available(void);
|
||||
int processInput(void);
|
||||
/* serial send handling */
|
||||
void sendAnalog(byte pin, int value);
|
||||
void sendDigital(byte pin, int value); // TODO implement this
|
||||
void sendDigitalPort(byte portNumber, int portData);
|
||||
void sendString(const char* string);
|
||||
void sendString(byte command, const char* string);
|
||||
void sendSysex(byte command, byte bytec, byte* bytev);
|
||||
/* attach & detach callback functions to messages */
|
||||
void attach(byte command, callbackFunction newFunction);
|
||||
void attach(byte command, systemResetCallbackFunction newFunction);
|
||||
void attach(byte command, stringCallbackFunction newFunction);
|
||||
void attach(byte command, sysexCallbackFunction newFunction);
|
||||
void detach(byte command);
|
||||
|
||||
private:
|
||||
Adafruit_BLE_UART &FirmataSerial;
|
||||
/* firmware name and version */
|
||||
byte firmwareVersionCount;
|
||||
byte *firmwareVersionVector;
|
||||
/* input message handling */
|
||||
byte waitForData; // this flag says the next serial input will be data
|
||||
byte executeMultiByteCommand; // execute this after getting multi-byte data
|
||||
byte multiByteChannel; // channel data for multiByteCommands
|
||||
byte storedInputData[MAX_DATA_BYTES]; // multi-byte data
|
||||
/* sysex */
|
||||
boolean parsingSysex;
|
||||
int sysexBytesRead;
|
||||
/* callback functions */
|
||||
callbackFunction currentAnalogCallback;
|
||||
callbackFunction currentDigitalCallback;
|
||||
callbackFunction currentReportAnalogCallback;
|
||||
callbackFunction currentReportDigitalCallback;
|
||||
callbackFunction currentPinModeCallback;
|
||||
systemResetCallbackFunction currentSystemResetCallback;
|
||||
stringCallbackFunction currentStringCallback;
|
||||
sysexCallbackFunction currentSysexCallback;
|
||||
|
||||
/* private methods ------------------------------ */
|
||||
void processSysexMessage(void);
|
||||
void systemReset(void);
|
||||
void pin13strobe(int count, int onInterval, int offInterval);
|
||||
void sendValueAsTwo7bitBytes(int value);
|
||||
void startSysex(void);
|
||||
void endSysex(void);
|
||||
};
|
||||
|
||||
extern Adafruit_BLE_FirmataClass BLE_Firmata;
|
||||
|
||||
/*==============================================================================
|
||||
* MACROS
|
||||
*============================================================================*/
|
||||
|
||||
/* shortcut for setFirmwareNameAndVersion() that uses __FILE__ to set the
|
||||
* firmware name. It needs to be a macro so that __FILE__ is included in the
|
||||
* firmware source file rather than the library source file.
|
||||
*/
|
||||
#define setFirmwareVersion(x, y) setFirmwareNameAndVersion(__FILE__, x, y)
|
||||
|
||||
#endif /* BLE_Firmata_h */
|
||||
|
||||
250
Projects/libraries/Installed_libs/Adafruit_BLEFirmata/Boards.h
Executable file
250
Projects/libraries/Installed_libs/Adafruit_BLEFirmata/Boards.h
Executable file
@@ -0,0 +1,250 @@
|
||||
/* Boards.h - Hardware Abstraction Layer for Firmata library */
|
||||
|
||||
#ifndef BLE_Firmata_Boards_h
|
||||
#define BLE_Firmata_Boards_h
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h" // for digitalRead, digitalWrite, etc
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
// Normally Servo.h must be included before Firmata.h (which then includes
|
||||
// this file). If Servo.h wasn't included, this allows the code to still
|
||||
// compile, but without support for any Servos. Hopefully that's what the
|
||||
// user intended by not including Servo.h
|
||||
#ifndef MAX_SERVOS
|
||||
#define MAX_SERVOS 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
Firmata Hardware Abstraction Layer
|
||||
|
||||
Firmata is built on top of the hardware abstraction functions of Arduino,
|
||||
specifically digitalWrite, digitalRead, analogWrite, analogRead, and
|
||||
pinMode. While these functions offer simple integer pin numbers, Firmata
|
||||
needs more information than is provided by Arduino. This file provides
|
||||
all other hardware specific details. To make Firmata support a new board,
|
||||
only this file should require editing.
|
||||
|
||||
The key concept is every "pin" implemented by Firmata may be mapped to
|
||||
any pin as implemented by Arduino. Usually a simple 1-to-1 mapping is
|
||||
best, but such mapping should not be assumed. This hardware abstraction
|
||||
layer allows Firmata to implement any number of pins which map onto the
|
||||
Arduino implemented pins in almost any arbitrary way.
|
||||
|
||||
|
||||
General Constants:
|
||||
|
||||
These constants provide basic information Firmata requires.
|
||||
|
||||
TOTAL_PINS: The total number of pins Firmata implemented by Firmata.
|
||||
Usually this will match the number of pins the Arduino functions
|
||||
implement, including any pins pins capable of analog or digital.
|
||||
However, Firmata may implement any number of pins. For example,
|
||||
on Arduino Mini with 8 analog inputs, 6 of these may be used
|
||||
for digital functions, and 2 are analog only. On such boards,
|
||||
Firmata can implement more pins than Arduino's pinMode()
|
||||
function, in order to accommodate those special pins. The
|
||||
Firmata protocol supports a maximum of 128 pins, so this
|
||||
constant must not exceed 128.
|
||||
|
||||
TOTAL_ANALOG_PINS: The total number of analog input pins implemented.
|
||||
The Firmata protocol allows up to 16 analog inputs, accessed
|
||||
using offsets 0 to 15. Because Firmata presents the analog
|
||||
inputs using different offsets than the actual pin numbers
|
||||
(a legacy of Arduino's analogRead function, and the way the
|
||||
analog input capable pins are physically labeled on all
|
||||
Arduino boards), the total number of analog input signals
|
||||
must be specified. 16 is the maximum.
|
||||
|
||||
VERSION_BLINK_PIN: When Firmata starts up, it will blink the version
|
||||
number. This constant is the Arduino pin number where a
|
||||
LED is connected.
|
||||
|
||||
|
||||
Pin Mapping Macros:
|
||||
|
||||
These macros provide the mapping between pins as implemented by
|
||||
Firmata protocol and the actual pin numbers used by the Arduino
|
||||
functions. Even though such mappings are often simple, pin
|
||||
numbers received by Firmata protocol should always be used as
|
||||
input to these macros, and the result of the macro should be
|
||||
used with with any Arduino function.
|
||||
|
||||
When Firmata is extended to support a new pin mode or feature,
|
||||
a pair of macros should be added and used for all hardware
|
||||
access. For simple 1:1 mapping, these macros add no actual
|
||||
overhead, yet their consistent use allows source code which
|
||||
uses them consistently to be easily adapted to all other boards
|
||||
with different requirements.
|
||||
|
||||
IS_PIN_XXXX(pin): The IS_PIN macros resolve to true or non-zero
|
||||
if a pin as implemented by Firmata corresponds to a pin
|
||||
that actually implements the named feature.
|
||||
|
||||
PIN_TO_XXXX(pin): The PIN_TO macros translate pin numbers as
|
||||
implemented by Firmata to the pin numbers needed as inputs
|
||||
to the Arduino functions. The corresponding IS_PIN macro
|
||||
should always be tested before using a PIN_TO macro, so
|
||||
these macros only need to handle valid Firmata pin
|
||||
numbers for the named feature.
|
||||
|
||||
|
||||
Port Access Inline Funtions:
|
||||
|
||||
For efficiency, Firmata protocol provides access to digital
|
||||
input and output pins grouped by 8 bit ports. When these
|
||||
groups of 8 correspond to actual 8 bit ports as implemented
|
||||
by the hardware, these inline functions can provide high
|
||||
speed direct port access. Otherwise, a default implementation
|
||||
using 8 calls to digitalWrite or digitalRead is used.
|
||||
|
||||
When porting Firmata to a new board, it is recommended to
|
||||
use the default functions first and focus only on the constants
|
||||
and macros above. When those are working, if optimized port
|
||||
access is desired, these inline functions may be extended.
|
||||
The recommended approach defines a symbol indicating which
|
||||
optimization to use, and then conditional complication is
|
||||
used within these functions.
|
||||
|
||||
readPort(port, bitmask): Read an 8 bit port, returning the value.
|
||||
port: The port number, Firmata pins port*8 to port*8+7
|
||||
bitmask: The actual pins to read, indicated by 1 bits.
|
||||
|
||||
writePort(port, value, bitmask): Write an 8 bit port.
|
||||
port: The port number, Firmata pins port*8 to port*8+7
|
||||
value: The 8 bit value to write
|
||||
bitmask: The actual pins to write, indicated by 1 bits.
|
||||
*/
|
||||
|
||||
/*==============================================================================
|
||||
* Board Specific Configuration
|
||||
*============================================================================*/
|
||||
|
||||
#ifndef digitalPinHasPWM
|
||||
#define digitalPinHasPWM(p) IS_PIN_DIGITAL(p)
|
||||
#endif
|
||||
|
||||
// Arduino Duemilanove, Diecimila, and NG
|
||||
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
|
||||
#if defined(NUM_ANALOG_INPUTS) && NUM_ANALOG_INPUTS == 6
|
||||
#define TOTAL_ANALOG_PINS 6
|
||||
#define TOTAL_PINS 22 // 14 digital (not all are 'digital/available') + 6 analog
|
||||
#else
|
||||
#define TOTAL_ANALOG_PINS 8
|
||||
#define TOTAL_PINS 22 // 14 digital + 8 analog
|
||||
#endif
|
||||
|
||||
#define VERSION_BLINK_PIN 99
|
||||
// we dont use digital 2 or 9, 10, 11, 12, 13 -> BTLE link
|
||||
#define IS_PIN_DIGITAL(p) (((p) >= 3 && (p) <= 8) || ((p) >= 14 && (p) <= 19 ))
|
||||
#define IS_PIN_ANALOG(p) ((p) >= 14 && (p) < 14 + TOTAL_ANALOG_PINS)
|
||||
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
|
||||
#define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) - 2 < MAX_SERVOS)
|
||||
#define IS_PIN_I2C(p) ((p) == 18 || (p) == 19)
|
||||
#define PIN_TO_DIGITAL(p) (p)
|
||||
#define PIN_TO_ANALOG(p) ((p) - 14)
|
||||
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
|
||||
#define PIN_TO_SERVO(p) ((p) - 2)
|
||||
#define ARDUINO_PINOUT_OPTIMIZE 0
|
||||
|
||||
|
||||
// Arduino Mega
|
||||
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||
#define TOTAL_ANALOG_PINS 16
|
||||
#define TOTAL_PINS 70 // 54 digital + 16 analog
|
||||
#define VERSION_BLINK_PIN 13
|
||||
#define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) < TOTAL_PINS)
|
||||
#define IS_PIN_ANALOG(p) ((p) >= 54 && (p) < TOTAL_PINS)
|
||||
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
|
||||
#define IS_PIN_SERVO(p) ((p) >= 2 && (p) - 2 < MAX_SERVOS)
|
||||
#define IS_PIN_I2C(p) ((p) == 20 || (p) == 21)
|
||||
#define PIN_TO_DIGITAL(p) (p)
|
||||
#define PIN_TO_ANALOG(p) ((p) - 54)
|
||||
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
|
||||
#define PIN_TO_SERVO(p) ((p) - 2)
|
||||
|
||||
|
||||
// anything else
|
||||
#else
|
||||
#error "Please edit Boards.h with a hardware abstraction for this board"
|
||||
#endif
|
||||
|
||||
|
||||
/*==============================================================================
|
||||
* readPort() - Read an 8 bit port
|
||||
*============================================================================*/
|
||||
|
||||
static inline unsigned char readPort(byte, byte) __attribute__((always_inline, unused));
|
||||
static inline unsigned char readPort(byte port, byte bitmask)
|
||||
{
|
||||
unsigned char out=0, pin=port*8;
|
||||
if (IS_PIN_DIGITAL(pin+0) && (bitmask & 0x01) && digitalRead(PIN_TO_DIGITAL(pin+0))) out |= 0x01;
|
||||
if (IS_PIN_DIGITAL(pin+1) && (bitmask & 0x02) && digitalRead(PIN_TO_DIGITAL(pin+1))) out |= 0x02;
|
||||
if (IS_PIN_DIGITAL(pin+2) && (bitmask & 0x04) && digitalRead(PIN_TO_DIGITAL(pin+2))) out |= 0x04;
|
||||
if (IS_PIN_DIGITAL(pin+3) && (bitmask & 0x08) && digitalRead(PIN_TO_DIGITAL(pin+3))) out |= 0x08;
|
||||
if (IS_PIN_DIGITAL(pin+4) && (bitmask & 0x10) && digitalRead(PIN_TO_DIGITAL(pin+4))) out |= 0x10;
|
||||
if (IS_PIN_DIGITAL(pin+5) && (bitmask & 0x20) && digitalRead(PIN_TO_DIGITAL(pin+5))) out |= 0x20;
|
||||
if (IS_PIN_DIGITAL(pin+6) && (bitmask & 0x40) && digitalRead(PIN_TO_DIGITAL(pin+6))) out |= 0x40;
|
||||
if (IS_PIN_DIGITAL(pin+7) && (bitmask & 0x80) && digitalRead(PIN_TO_DIGITAL(pin+7))) out |= 0x80;
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
/*==============================================================================
|
||||
* writePort() - Write an 8 bit port, only touch pins specified by a bitmask
|
||||
*============================================================================*/
|
||||
|
||||
static inline unsigned char writePort(byte, byte, byte) __attribute__((always_inline, unused));
|
||||
static inline unsigned char writePort(byte port, byte value, byte bitmask)
|
||||
{
|
||||
#if defined(ARDUINO_PINOUT_OPTIMIZE)
|
||||
if (port == 0) {
|
||||
bitmask = bitmask & 0xFC; // do not touch Tx & Rx pins
|
||||
byte valD = value & bitmask;
|
||||
byte maskD = ~bitmask;
|
||||
cli();
|
||||
PORTD = (PORTD & maskD) | valD;
|
||||
sei();
|
||||
} else if (port == 1) {
|
||||
byte valB = (value & bitmask) & 0x3F;
|
||||
byte valC = (value & bitmask) >> 6;
|
||||
byte maskB = ~(bitmask & 0x3F);
|
||||
byte maskC = ~((bitmask & 0xC0) >> 6);
|
||||
cli();
|
||||
PORTB = (PORTB & maskB) | valB;
|
||||
PORTC = (PORTC & maskC) | valC;
|
||||
sei();
|
||||
} else if (port == 2) {
|
||||
bitmask = bitmask & 0x0F;
|
||||
byte valC = (value & bitmask) << 2;
|
||||
byte maskC = ~(bitmask << 2);
|
||||
cli();
|
||||
PORTC = (PORTC & maskC) | valC;
|
||||
sei();
|
||||
}
|
||||
#else
|
||||
byte pin=port*8;
|
||||
for (uint8_t i=0; i<8; i++) {
|
||||
if (bitmask & (1 << i)) {
|
||||
// dont touch non-digital pins
|
||||
if (IS_PIN_DIGITAL(pin+i))
|
||||
digitalWrite(PIN_TO_DIGITAL(pin+i), (value & (1 << i)));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef TOTAL_PORTS
|
||||
#define TOTAL_PORTS ((TOTAL_PINS + 7) / 8)
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* BLE_Firmata_Boards_h */
|
||||
|
||||
458
Projects/libraries/Installed_libs/Adafruit_BLEFirmata/LICENSE.txt
Executable file
458
Projects/libraries/Installed_libs/Adafruit_BLEFirmata/LICENSE.txt
Executable file
@@ -0,0 +1,458 @@
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
125
Projects/libraries/Installed_libs/Adafruit_BLEFirmata/README.md
Executable file
125
Projects/libraries/Installed_libs/Adafruit_BLEFirmata/README.md
Executable file
@@ -0,0 +1,125 @@
|
||||
#Firmata
|
||||
|
||||
Firmata is a protocol for communicating with microcontrollers from software on a host computer. The [protocol](http://firmata.org/wiki/Protocol) can be implemented in firmware on any microcontroller architecture as well as software on any host computer software package. The arduino repository described here is a Firmata library for Arduino and Arduino-compatible devices. See the [firmata wiki](http://firmata.org/wiki/Main_Page) for additional informataion. If you would like to contribute to Firmata, please see the [Contributing](#contributing) section below.
|
||||
|
||||
##Usage
|
||||
|
||||
There are two main models of usage of Firmata. In one model, the author of the Arduino sketch uses the various methods provided by the Firmata library to selectively send and receive data between the Arduino device and the software running on the host computer. For example, a user can send analog data to the host using ``` Firmata.sendAnalog(analogPin, analogRead(analogPin)) ``` or send data packed in a string using ``` Firmata.sendString(stringToSend) ```. See File -> Examples -> Firmata -> AnalogFirmata & EchoString respectively for examples.
|
||||
|
||||
The second and more common model is to load a general purpose sketch called StandardFirmata on the Arduino board and then use the host computer exclusively to interact with the Arduino board. StandardFirmata is located in the Arduino IDE in File -> Examples -> Firmata.
|
||||
|
||||
##Firmata Client Libraries
|
||||
Most of the time you will be interacting with arduino with a client library on the host computers. Several Firmata client libraries have been implemented in a variety of popular programming languages:
|
||||
|
||||
* procesing
|
||||
* [https://github.com/firmata/processing]
|
||||
* [http://funnel.cc]
|
||||
* python
|
||||
* [https://github.com/firmata/pyduino]
|
||||
* [https://github.com/lupeke/python-firmata]
|
||||
* [https://github.com/tino/pyFirmata]
|
||||
* perl
|
||||
* [https://github.com/ntruchsess/perl-firmata]
|
||||
* [https://github.com/rcaputo/rx-firmata]
|
||||
* ruby
|
||||
* [https://github.com/hardbap/firmata]
|
||||
* [https://github.com/PlasticLizard/rufinol]
|
||||
* [http://funnel.cc]
|
||||
* clojure
|
||||
* [https://github.com/nakkaya/clodiuno]
|
||||
* javascript
|
||||
* [https://github.com/jgautier/firmata]
|
||||
* [http://breakoutjs.com]
|
||||
* [https://github.com/rwldrn/johnny-five]
|
||||
* java
|
||||
* [https://github.com/4ntoine/Firmata]
|
||||
* [https://github.com/shigeodayo/Javarduino]
|
||||
* .NET
|
||||
* [http://www.imagitronics.org/projects/firmatanet/]
|
||||
* Flash/AS3
|
||||
* [http://funnel.cc]
|
||||
* [http://code.google.com/p/as3glue/]
|
||||
* PHP
|
||||
* [https://bitbucket.org/ThomasWeinert/carica-firmata]
|
||||
|
||||
Note: The above libraries may support various versions of the Firmata protocol and therefore may not support all features of the latest Firmata spec nor all arduino and arduino-compatible boards. Refer to the respective projects for details.
|
||||
|
||||
##Updating Firmata in the Arduino IDE (< Arduino 1.5)
|
||||
The version of firmata in the Arduino IDE contains an outdated version of Firmata. To update Firmata, clone the repo into the location of firmata in the arduino IDE or download the latest [tagged version](https://github.com/firmata/arduino/tags) (stable), rename the folder to "Firmata" and replace the existing Firmata folder in your Ardino application.
|
||||
|
||||
**Mac OSX**:
|
||||
|
||||
```bash
|
||||
$ rm -r /Applications/Arduino.app/Contents/Resources/Java/libraries/Firmata
|
||||
$ git clone git@github.com:firmata/arduino.git /Applications/Arduino.app/Contents/Resources/Java/libraries/Firmata
|
||||
```
|
||||
|
||||
If you are downloading the latest tagged version of Firmata, rename it to "Firmata" and copy to /Applications/Arduino.app/Contents/Resources/Java/libraries/ overwriting the existing Firmata directory. Right-click (or conrol + click) on the Arduino application and choose "Show Package Contents" and navigate to the libraries directory.
|
||||
|
||||
**Windows**:
|
||||
|
||||
Using the Git Shell application installed with [GitHub for Windows](http://windows.github.com/) (set default shell in options to Git Bash) or other command line based git tool:
|
||||
|
||||
update the path and arduino version as necessary
|
||||
```bash
|
||||
$ rm -r c:/Program\ Files/arduino-1.x/libraries/Firmata
|
||||
$ git clone git@github.com:firmata/arduino.git c:/Program\ Files/arduino-1.x/libraries/Firmata
|
||||
```
|
||||
|
||||
Note: If you use GitHub for Windows, you must clone the firmata/arduino repository using the Git Shell application as described above. You can use the Github for Windows GUI only after you have cloned the repository. Drag the Firmata file into the Github for Windows GUI to track it.
|
||||
|
||||
**Linux**:
|
||||
|
||||
update the path and arduino version as necessary
|
||||
```bash
|
||||
$ rm -r ~/arduino-1.x/libraries/Firmata
|
||||
$ git clone git@github.com:firmata/arduino.git ~/arduino-1.x/libraries/Firmata
|
||||
```
|
||||
|
||||
##Updating Firmata in the Arduino IDE (>= Arduino 1.5.2)
|
||||
As of Arduino 1.5.2 and there are separate library directories for the sam and
|
||||
avr architectures. To update Firmata in Arduino 1.5.2 or higher, follow the
|
||||
instructions above for pre Arduino 1.5 versions but update the path as follows:
|
||||
|
||||
**Mac OSX**:
|
||||
```
|
||||
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/libraries/Firmata
|
||||
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/sam/libraries/Firmata
|
||||
```
|
||||
|
||||
**Windows**:
|
||||
```
|
||||
/Program\ Files/arduino-1.5.x/hardware/arduino/avr/libraries/Firmata
|
||||
/Program\ Files/arduino-1.5.x/hardware/arduino/sam/libraries/Firmata
|
||||
```
|
||||
|
||||
**Linux**
|
||||
```
|
||||
~/arduino-1.5.x/hardware/arduino/avr/libraries/Firmata
|
||||
~/arduino-1.5.x/hardware/arduino/sam/libraries/Firmata
|
||||
```
|
||||
|
||||
<a name="contributing" />
|
||||
##Contributing
|
||||
|
||||
If you discover a bug or would like to propose a new feature, please open a new [issue](https://github.com/firmata/arduino/issues?sort=created&state=open). Due to the limited memory of standard Arduino boards we cannot add every requested feature to StandardFirmata. Requests to add new features to StandardFirmata will be evaluated by the Firmata developers. However it is still possible to add new features to other Firmata implementations (Firmata is a protocol whereas StandardFirmata is just one of many possible implementations).
|
||||
|
||||
To contribute, fork this respository and create a new topic branch for the bug, feature or other existing issue you are addressing. Submit the pull request against the *dev* branch.
|
||||
|
||||
If you would like to contribute but don't have a specific bugfix or new feature to contribute, you can take on an existing issue, see issues labeled "pull-request-encouraged". Add a comment to the issue to express your intent to begin work and/or to get any additional information about the issue.
|
||||
|
||||
You must thorougly test your contributed code. In your pull request, describe tests performed to ensure that no existing code is broken and that any changes maintain backwards compatibility with the existing api. Test on multiple Arduino board variants if possible. We hope to enable some form of automated (or at least semi-automated) testing in the future, but for now any tests will need to be executed manually by the contributor and reviewsers.
|
||||
|
||||
Maintain the existing code style:
|
||||
|
||||
- Indentation is 2 spaces
|
||||
- Use spaces instead of tabs
|
||||
- Use camel case for both private and public properties and methods
|
||||
- Document functions (specific doc style is TBD... for now just be sure to document)
|
||||
- Insert first block bracket on line following the function definition:
|
||||
|
||||
<pre>void someFunction()
|
||||
{
|
||||
// do something
|
||||
}
|
||||
</pre>
|
||||
@@ -0,0 +1,458 @@
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
@@ -0,0 +1,273 @@
|
||||
# Arduino makefile
|
||||
#
|
||||
# This makefile allows you to build sketches from the command line
|
||||
# without the Arduino environment (or Java).
|
||||
#
|
||||
# The Arduino environment does preliminary processing on a sketch before
|
||||
# compiling it. If you're using this makefile instead, you'll need to do
|
||||
# a few things differently:
|
||||
#
|
||||
# - Give your program's file a .cpp extension (e.g. foo.cpp).
|
||||
#
|
||||
# - Put this line at top of your code: #include <WProgram.h>
|
||||
#
|
||||
# - Write prototypes for all your functions (or define them before you
|
||||
# call them). A prototype declares the types of parameters a
|
||||
# function will take and what type of value it will return. This
|
||||
# means that you can have a call to a function before the definition
|
||||
# of the function. A function prototype looks like the first line of
|
||||
# the function, with a semi-colon at the end. For example:
|
||||
# int digitalRead(int pin);
|
||||
#
|
||||
# Instructions for using the makefile:
|
||||
#
|
||||
# 1. Copy this file into the folder with your sketch.
|
||||
#
|
||||
# 2. Below, modify the line containing "TARGET" to refer to the name of
|
||||
# of your program's file without an extension (e.g. TARGET = foo).
|
||||
#
|
||||
# 3. Modify the line containg "ARDUINO" to point the directory that
|
||||
# contains the Arduino core (for normal Arduino installations, this
|
||||
# is the hardware/cores/arduino sub-directory).
|
||||
#
|
||||
# 4. Modify the line containing "PORT" to refer to the filename
|
||||
# representing the USB or serial connection to your Arduino board
|
||||
# (e.g. PORT = /dev/tty.USB0). If the exact name of this file
|
||||
# changes, you can use * as a wildcard (e.g. PORT = /dev/tty.USB*).
|
||||
#
|
||||
# 5. At the command line, change to the directory containing your
|
||||
# program's file and the makefile.
|
||||
#
|
||||
# 6. Type "make" and press enter to compile/verify your program.
|
||||
#
|
||||
# 7. Type "make upload", reset your Arduino board, and press enter to
|
||||
# upload your program to the Arduino board.
|
||||
#
|
||||
# $Id: Makefile,v 1.7 2007/04/13 05:28:23 eighthave Exp $
|
||||
|
||||
PORT = /dev/tty.usbserial-*
|
||||
TARGET := $(shell pwd | sed 's|.*/\(.*\)|\1|')
|
||||
ARDUINO = /Applications/arduino
|
||||
ARDUINO_SRC = $(ARDUINO)/hardware/cores/arduino
|
||||
ARDUINO_LIB_SRC = $(ARDUINO)/hardware/libraries
|
||||
ARDUINO_TOOLS = $(ARDUINO)/hardware/tools
|
||||
INCLUDE = -I$(ARDUINO_SRC) -I$(ARDUINO)/hardware/tools/avr/avr/include \
|
||||
-I$(ARDUINO_LIB_SRC)/EEPROM \
|
||||
-I$(ARDUINO_LIB_SRC)/Firmata \
|
||||
-I$(ARDUINO_LIB_SRC)/Matrix \
|
||||
-I$(ARDUINO_LIB_SRC)/Servo \
|
||||
-I$(ARDUINO_LIB_SRC)/Wire \
|
||||
-I$(ARDUINO_LIB_SRC)
|
||||
SRC = $(wildcard $(ARDUINO_SRC)/*.c)
|
||||
CXXSRC = applet/$(TARGET).cpp $(ARDUINO_SRC)/HardwareSerial.cpp \
|
||||
$(ARDUINO_LIB_SRC)/EEPROM/EEPROM.cpp \
|
||||
$(ARDUINO_LIB_SRC)/Firmata/Firmata.cpp \
|
||||
$(ARDUINO_LIB_SRC)/Servo/Servo.cpp \
|
||||
$(ARDUINO_SRC)/Print.cpp \
|
||||
$(ARDUINO_SRC)/WMath.cpp
|
||||
HEADERS = $(wildcard $(ARDUINO_SRC)/*.h) $(wildcard $(ARDUINO_LIB_SRC)/*/*.h)
|
||||
|
||||
MCU = atmega168
|
||||
#MCU = atmega8
|
||||
F_CPU = 16000000
|
||||
FORMAT = ihex
|
||||
UPLOAD_RATE = 19200
|
||||
|
||||
# Name of this Makefile (used for "make depend").
|
||||
MAKEFILE = Makefile
|
||||
|
||||
# Debugging format.
|
||||
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
|
||||
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
|
||||
DEBUG = stabs
|
||||
|
||||
OPT = s
|
||||
|
||||
# Place -D or -U options here
|
||||
CDEFS = -DF_CPU=$(F_CPU)
|
||||
CXXDEFS = -DF_CPU=$(F_CPU)
|
||||
|
||||
# Compiler flag to set the C Standard level.
|
||||
# c89 - "ANSI" C
|
||||
# gnu89 - c89 plus GCC extensions
|
||||
# c99 - ISO C99 standard (not yet fully implemented)
|
||||
# gnu99 - c99 plus GCC extensions
|
||||
CSTANDARD = -std=gnu99
|
||||
CDEBUG = -g$(DEBUG)
|
||||
CWARN = -Wall -Wstrict-prototypes
|
||||
CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
|
||||
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
|
||||
|
||||
CFLAGS = $(CDEBUG) $(CDEFS) $(INCLUDE) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
|
||||
CXXFLAGS = $(CDEFS) $(INCLUDE) -O$(OPT)
|
||||
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
|
||||
LDFLAGS =
|
||||
|
||||
|
||||
# Programming support using avrdude. Settings and variables.
|
||||
AVRDUDE_PROGRAMMER = stk500
|
||||
AVRDUDE_PORT = $(PORT)
|
||||
AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex
|
||||
AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
|
||||
-b $(UPLOAD_RATE) -q -V
|
||||
|
||||
# Program settings
|
||||
ARDUINO_AVR_BIN = $(ARDUINO_TOOLS)/avr/bin
|
||||
CC = $(ARDUINO_AVR_BIN)/avr-gcc
|
||||
CXX = $(ARDUINO_AVR_BIN)/avr-g++
|
||||
OBJCOPY = $(ARDUINO_AVR_BIN)/avr-objcopy
|
||||
OBJDUMP = $(ARDUINO_AVR_BIN)/avr-objdump
|
||||
SIZE = $(ARDUINO_AVR_BIN)/avr-size
|
||||
NM = $(ARDUINO_AVR_BIN)/avr-nm
|
||||
#AVRDUDE = $(ARDUINO_AVR_BIN)/avrdude
|
||||
AVRDUDE = avrdude
|
||||
REMOVE = rm -f
|
||||
MV = mv -f
|
||||
|
||||
# Define all object files.
|
||||
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
|
||||
|
||||
# Define all listing files.
|
||||
LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
|
||||
|
||||
# Combine all necessary flags and optional flags.
|
||||
# Add target processor to flags.
|
||||
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
|
||||
ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS)
|
||||
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
|
||||
|
||||
|
||||
# Default target.
|
||||
all: build
|
||||
|
||||
build: applet/$(TARGET).hex
|
||||
|
||||
eep: applet/$(TARGET).eep
|
||||
lss: applet/$(TARGET).lss
|
||||
sym: applet/$(TARGET).sym
|
||||
|
||||
|
||||
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
|
||||
COFFCONVERT=$(OBJCOPY) --debugging \
|
||||
--change-section-address .data-0x800000 \
|
||||
--change-section-address .bss-0x800000 \
|
||||
--change-section-address .noinit-0x800000 \
|
||||
--change-section-address .eeprom-0x810000
|
||||
|
||||
|
||||
coff: applet/$(TARGET).elf
|
||||
$(COFFCONVERT) -O coff-avr applet/$(TARGET).elf applet/$(TARGET).cof
|
||||
|
||||
|
||||
extcoff: applet/$(TARGET).elf
|
||||
$(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf applet/$(TARGET).cof
|
||||
|
||||
|
||||
.SUFFIXES: .elf .hex .eep .lss .sym .pde
|
||||
|
||||
.elf.hex:
|
||||
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
|
||||
|
||||
.elf.eep:
|
||||
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
|
||||
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
|
||||
|
||||
# Create extended listing file from ELF output file.
|
||||
.elf.lss:
|
||||
$(OBJDUMP) -h -S $< > $@
|
||||
|
||||
# Create a symbol table from ELF output file.
|
||||
.elf.sym:
|
||||
$(NM) -n $< > $@
|
||||
|
||||
|
||||
# Compile: create object files from C++ source files.
|
||||
.cpp.o: $(HEADERS)
|
||||
$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
.c.o: $(HEADERS)
|
||||
$(CC) -c $(ALL_CFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Compile: create assembler files from C source files.
|
||||
.c.s:
|
||||
$(CC) -S $(ALL_CFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Assemble: create object files from assembler source files.
|
||||
.S.o:
|
||||
$(CC) -c $(ALL_ASFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
applet/$(TARGET).cpp: $(TARGET).pde
|
||||
test -d applet || mkdir applet
|
||||
echo '#include "WProgram.h"' > applet/$(TARGET).cpp
|
||||
echo '#include "avr/interrupt.h"' >> applet/$(TARGET).cpp
|
||||
sed -n 's|^\(void .*)\).*|\1;|p' $(TARGET).pde | grep -v 'setup()' | \
|
||||
grep -v 'loop()' >> applet/$(TARGET).cpp
|
||||
cat $(TARGET).pde >> applet/$(TARGET).cpp
|
||||
cat $(ARDUINO_SRC)/main.cxx >> applet/$(TARGET).cpp
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
applet/$(TARGET).elf: applet/$(TARGET).cpp $(OBJ)
|
||||
$(CC) $(ALL_CFLAGS) $(OBJ) -lm --output $@ $(LDFLAGS)
|
||||
# $(CC) $(ALL_CFLAGS) $(OBJ) $(ARDUINO_TOOLS)/avr/avr/lib/avr5/crtm168.o --output $@ $(LDFLAGS)
|
||||
|
||||
pd_close_serial:
|
||||
echo 'close;' | /Applications/Pd-extended.app/Contents/Resources/bin/pdsend 34567 || true
|
||||
|
||||
# Program the device.
|
||||
upload: applet/$(TARGET).hex
|
||||
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
|
||||
|
||||
|
||||
pd_test: build pd_close_serial upload
|
||||
|
||||
# Target: clean project.
|
||||
clean:
|
||||
$(REMOVE) -- applet/$(TARGET).hex applet/$(TARGET).eep \
|
||||
applet/$(TARGET).cof applet/$(TARGET).elf $(TARGET).map \
|
||||
applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp \
|
||||
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
|
||||
rmdir -- applet
|
||||
|
||||
depend:
|
||||
if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
|
||||
then \
|
||||
sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
|
||||
$(MAKEFILE).$$$$ && \
|
||||
$(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
|
||||
fi
|
||||
echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
|
||||
>> $(MAKEFILE); \
|
||||
$(CC) -M -mmcu=$(MCU) $(CDEFS) $(INCLUDE) $(SRC) $(ASRC) >> $(MAKEFILE)
|
||||
|
||||
.PHONY: all build eep lss sym coff extcoff clean depend pd_close_serial pd_test
|
||||
|
||||
# for emacs
|
||||
etags:
|
||||
make etags_`uname -s`
|
||||
etags *.pde \
|
||||
$(ARDUINO_SRC)/*.[ch] \
|
||||
$(ARDUINO_SRC)/*.cpp \
|
||||
$(ARDUINO_LIB_SRC)/*/*.[ch] \
|
||||
$(ARDUINO_LIB_SRC)/*/*.cpp \
|
||||
$(ARDUINO)/hardware/tools/avr/avr/include/avr/*.[ch] \
|
||||
$(ARDUINO)/hardware/tools/avr/avr/include/*.[ch]
|
||||
|
||||
etags_Darwin:
|
||||
# etags -a
|
||||
|
||||
etags_Linux:
|
||||
# etags -a /usr/include/*.h linux/input.h /usr/include/sys/*.h
|
||||
|
||||
etags_MINGW:
|
||||
# etags -a /usr/include/*.h /usr/include/sys/*.h
|
||||
|
||||
|
||||
path:
|
||||
echo $(PATH)
|
||||
echo $$PATH
|
||||
|
||||
@@ -0,0 +1,738 @@
|
||||
/*
|
||||
* Firmata is a generic protocol for communicating with microcontrollers
|
||||
* from software on a host computer. It is intended to work with
|
||||
* any host computer software package.
|
||||
*
|
||||
* This version is modified to specifically work with Adafruit's BLE
|
||||
* library. It no longer works over the standard "USB" connection!
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved.
|
||||
Copyright (C) 2010-2011 Paul Stoffregen. All rights reserved.
|
||||
Copyright (C) 2009 Shigeru Kobayashi. All rights reserved.
|
||||
Copyright (C) 2009-2011 Jeff Hoefs. All rights reserved.
|
||||
Copyright (C) 2014 Limor Fried/Kevin Townsend All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
See file LICENSE.txt for further informations on licensing terms.
|
||||
|
||||
formatted using the GNU C formatting and indenting
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO: use Program Control to load stored profiles from EEPROM
|
||||
*/
|
||||
|
||||
#include <Servo.h>
|
||||
#include <Wire.h>
|
||||
#include <SPI.h>
|
||||
#include <Adafruit_BLE_Firmata.h>
|
||||
#include "Adafruit_BLE_UART.h"
|
||||
|
||||
#define AUTO_INPUT_PULLUPS true
|
||||
|
||||
// Connect CLK/MISO/MOSI to hardware SPI
|
||||
// e.g. On UNO & compatible: CLK = 13, MISO = 12, MOSI = 11
|
||||
#define ADAFRUITBLE_REQ 10
|
||||
#define ADAFRUITBLE_RDY 2 // This should be an interrupt pin, on Uno thats #2 or #3
|
||||
#define ADAFRUITBLE_RST 9
|
||||
|
||||
// so we have digital 3-8 and analog 0-6
|
||||
|
||||
Adafruit_BLE_UART BLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
|
||||
|
||||
|
||||
// make one instance for the user to use
|
||||
Adafruit_BLE_FirmataClass BLE_Firmata(BLEserial);
|
||||
|
||||
|
||||
/*==============================================================================
|
||||
* GLOBAL VARIABLES
|
||||
*============================================================================*/
|
||||
|
||||
/* analog inputs */
|
||||
int analogInputsToReport = 0; // bitwise array to store pin reporting
|
||||
int lastAnalogReads[NUM_ANALOG_INPUTS];
|
||||
|
||||
/* digital input ports */
|
||||
byte reportPINs[TOTAL_PORTS]; // 1 = report this port, 0 = silence
|
||||
byte previousPINs[TOTAL_PORTS]; // previous 8 bits sent
|
||||
|
||||
/* pins configuration */
|
||||
byte pinConfig[TOTAL_PINS]; // configuration of every pin
|
||||
byte portConfigInputs[TOTAL_PORTS]; // each bit: 1 = pin in INPUT, 0 = anything else
|
||||
int pinState[TOTAL_PINS]; // any value that has been written
|
||||
|
||||
/* timer variables */
|
||||
unsigned long currentMillis; // store the current value from millis()
|
||||
unsigned long previousMillis; // for comparison with currentMillis
|
||||
int samplingInterval = 200; // how often to run the main loop (in ms)
|
||||
#define MINIMUM_SAMPLE_DELAY 150
|
||||
#define ANALOG_SAMPLE_DELAY 50
|
||||
|
||||
|
||||
/* i2c data */
|
||||
struct i2c_device_info {
|
||||
byte addr;
|
||||
byte reg;
|
||||
byte bytes;
|
||||
};
|
||||
|
||||
/* for i2c read continuous more */
|
||||
i2c_device_info query[MAX_QUERIES];
|
||||
|
||||
byte i2cRxData[32];
|
||||
boolean isI2CEnabled = false;
|
||||
signed char queryIndex = -1;
|
||||
unsigned int i2cReadDelayTime = 0; // default delay time between i2c read request and Wire.requestFrom()
|
||||
|
||||
Servo servos[MAX_SERVOS];
|
||||
/*==============================================================================
|
||||
* FUNCTIONS
|
||||
*============================================================================*/
|
||||
|
||||
void readAndReportData(byte address, int theRegister, byte numBytes) {
|
||||
// allow I2C requests that don't require a register read
|
||||
// for example, some devices using an interrupt pin to signify new data available
|
||||
// do not always require the register read so upon interrupt you call Wire.requestFrom()
|
||||
if (theRegister != REGISTER_NOT_SPECIFIED) {
|
||||
Wire.beginTransmission(address);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write((byte)theRegister);
|
||||
#else
|
||||
Wire.send((byte)theRegister);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
delayMicroseconds(i2cReadDelayTime); // delay is necessary for some devices such as WiiNunchuck
|
||||
} else {
|
||||
theRegister = 0; // fill the register with a dummy value
|
||||
}
|
||||
|
||||
Wire.requestFrom(address, numBytes); // all bytes are returned in requestFrom
|
||||
|
||||
// check to be sure correct number of bytes were returned by slave
|
||||
if(numBytes == Wire.available()) {
|
||||
i2cRxData[0] = address;
|
||||
i2cRxData[1] = theRegister;
|
||||
for (int i = 0; i < numBytes; i++) {
|
||||
#if ARDUINO >= 100
|
||||
i2cRxData[2 + i] = Wire.read();
|
||||
#else
|
||||
i2cRxData[2 + i] = Wire.receive();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(numBytes > Wire.available()) {
|
||||
BLE_Firmata.sendString("I2C Read Error: Too many bytes received");
|
||||
} else {
|
||||
BLE_Firmata.sendString("I2C Read Error: Too few bytes received");
|
||||
}
|
||||
}
|
||||
|
||||
// send slave address, register and received bytes
|
||||
BLE_Firmata.sendSysex(SYSEX_I2C_REPLY, numBytes + 2, i2cRxData);
|
||||
}
|
||||
|
||||
void outputPort(byte portNumber, byte portValue, byte forceSend)
|
||||
{
|
||||
// pins not configured as INPUT are cleared to zeros
|
||||
portValue = portValue & portConfigInputs[portNumber];
|
||||
// only send if the value is different than previously sent
|
||||
if(forceSend || previousPINs[portNumber] != portValue) {
|
||||
Serial.print(F("Sending update for port ")); Serial.print(portNumber); Serial.print(" = 0x"); Serial.println(portValue, HEX);
|
||||
BLE_Firmata.sendDigitalPort(portNumber, portValue);
|
||||
previousPINs[portNumber] = portValue;
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* check all the active digital inputs for change of state, then add any events
|
||||
* to the Serial output queue using Serial.print() */
|
||||
void checkDigitalInputs(boolean forceSend = false)
|
||||
{
|
||||
/* Using non-looping code allows constants to be given to readPort().
|
||||
* The compiler will apply substantial optimizations if the inputs
|
||||
* to readPort() are compile-time constants. */
|
||||
for (uint8_t i=0; i<TOTAL_PORTS; i++) {
|
||||
if (reportPINs[i]) {
|
||||
// Serial.print("Reporting on port "); Serial.print(i); Serial.print(" mask 0x"); Serial.println(portConfigInputs[i], HEX);
|
||||
uint8_t x = readPort(i, portConfigInputs[i]);
|
||||
// Serial.print("Read 0x"); Serial.println(x, HEX);
|
||||
outputPort(i, x, forceSend);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/* sets the pin mode to the correct state and sets the relevant bits in the
|
||||
* two bit-arrays that track Digital I/O and PWM status
|
||||
*/
|
||||
void setPinModeCallback(byte pin, int mode)
|
||||
{
|
||||
if ((pinConfig[pin] == I2C) && (isI2CEnabled) && (mode != I2C)) {
|
||||
// disable i2c so pins can be used for other functions
|
||||
// the following if statements should reconfigure the pins properly
|
||||
disableI2CPins();
|
||||
}
|
||||
if (IS_PIN_SERVO(pin) && mode != SERVO && servos[PIN_TO_SERVO(pin)].attached()) {
|
||||
servos[PIN_TO_SERVO(pin)].detach();
|
||||
}
|
||||
if (IS_PIN_ANALOG(pin)) {
|
||||
reportAnalogCallback(PIN_TO_ANALOG(pin), mode == ANALOG ? 1 : 0); // turn on/off reporting
|
||||
}
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
if (mode == INPUT) {
|
||||
portConfigInputs[pin/8] |= (1 << (pin & 7));
|
||||
} else {
|
||||
portConfigInputs[pin/8] &= ~(1 << (pin & 7));
|
||||
}
|
||||
// Serial.print(F("Setting pin #")); Serial.print(pin); Serial.print(F(" port config mask to = 0x"));
|
||||
// Serial.println(portConfigInputs[pin/8], HEX);
|
||||
}
|
||||
pinState[pin] = 0;
|
||||
switch(mode) {
|
||||
case ANALOG:
|
||||
if (IS_PIN_ANALOG(pin)) {
|
||||
Serial.print(F("Set pin #")); Serial.print(pin); Serial.println(F(" to analog"));
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver
|
||||
digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups
|
||||
}
|
||||
pinConfig[pin] = ANALOG;
|
||||
lastAnalogReads[PIN_TO_ANALOG(pin)] = -1;
|
||||
}
|
||||
break;
|
||||
case INPUT:
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
Serial.print(F("Set pin #")); Serial.print(pin); Serial.println(F(" to input"));
|
||||
pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver
|
||||
if (AUTO_INPUT_PULLUPS) {
|
||||
digitalWrite(PIN_TO_DIGITAL(pin), HIGH); // enable internal pull-ups
|
||||
} else {
|
||||
digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups
|
||||
}
|
||||
pinConfig[pin] = INPUT;
|
||||
|
||||
// force sending state immediately
|
||||
//delay(10);
|
||||
//checkDigitalInputs(true);
|
||||
}
|
||||
break;
|
||||
case OUTPUT:
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
Serial.print(F("Set pin #")); Serial.print(pin); Serial.println(F(" to output"));
|
||||
digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable PWM
|
||||
pinMode(PIN_TO_DIGITAL(pin), OUTPUT);
|
||||
pinConfig[pin] = OUTPUT;
|
||||
}
|
||||
break;
|
||||
case PWM:
|
||||
if (IS_PIN_PWM(pin)) {
|
||||
pinMode(PIN_TO_PWM(pin), OUTPUT);
|
||||
analogWrite(PIN_TO_PWM(pin), 0);
|
||||
pinConfig[pin] = PWM;
|
||||
}
|
||||
break;
|
||||
case SERVO:
|
||||
if (IS_PIN_SERVO(pin)) {
|
||||
pinConfig[pin] = SERVO;
|
||||
if (!servos[PIN_TO_SERVO(pin)].attached()) {
|
||||
servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case I2C:
|
||||
if (IS_PIN_I2C(pin)) {
|
||||
// mark the pin as i2c
|
||||
// the user must call I2C_CONFIG to enable I2C for a device
|
||||
pinConfig[pin] = I2C;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Serial.print(F("Unknown pin mode")); // TODO: put error msgs in EEPROM
|
||||
}
|
||||
// TODO: save status to EEPROM here, if changed
|
||||
}
|
||||
|
||||
void analogWriteCallback(byte pin, int value)
|
||||
{
|
||||
if (pin < TOTAL_PINS) {
|
||||
switch(pinConfig[pin]) {
|
||||
case SERVO:
|
||||
if (IS_PIN_SERVO(pin))
|
||||
servos[PIN_TO_SERVO(pin)].write(value);
|
||||
pinState[pin] = value;
|
||||
break;
|
||||
case PWM:
|
||||
if (IS_PIN_PWM(pin))
|
||||
analogWrite(PIN_TO_PWM(pin), value);
|
||||
pinState[pin] = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void digitalWriteCallback(byte port, int value)
|
||||
{
|
||||
byte pin, lastPin, mask=1, pinWriteMask=0;
|
||||
|
||||
if (port < TOTAL_PORTS) {
|
||||
// create a mask of the pins on this port that are writable.
|
||||
lastPin = port*8+8;
|
||||
if (lastPin > TOTAL_PINS) lastPin = TOTAL_PINS;
|
||||
for (pin=port*8; pin < lastPin; pin++) {
|
||||
// do not disturb non-digital pins (eg, Rx & Tx)
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
// only write to OUTPUT and INPUT (enables pullup)
|
||||
// do not touch pins in PWM, ANALOG, SERVO or other modes
|
||||
if (pinConfig[pin] == OUTPUT || pinConfig[pin] == INPUT) {
|
||||
pinWriteMask |= mask;
|
||||
pinState[pin] = ((byte)value & mask) ? 1 : 0;
|
||||
|
||||
if (AUTO_INPUT_PULLUPS && ( pinConfig[pin] == INPUT)) {
|
||||
value |= mask;
|
||||
}
|
||||
}
|
||||
}
|
||||
mask = mask << 1;
|
||||
}
|
||||
Serial.print(F("Write digital port #")); Serial.print(port);
|
||||
Serial.print(F(" = 0x")); Serial.print(value, HEX);
|
||||
Serial.print(F(" mask = 0x")); Serial.println(pinWriteMask, HEX);
|
||||
writePort(port, (byte)value, pinWriteMask);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/* sets bits in a bit array (int) to toggle the reporting of the analogIns
|
||||
*/
|
||||
//void FirmataClass::setAnalogPinReporting(byte pin, byte state) {
|
||||
//}
|
||||
void reportAnalogCallback(byte analogPin, int value)
|
||||
{
|
||||
if (analogPin < TOTAL_ANALOG_PINS) {
|
||||
if(value == 0) {
|
||||
analogInputsToReport = analogInputsToReport &~ (1 << analogPin);
|
||||
Serial.print(F("Stop reporting analog pin #")); Serial.println(analogPin);
|
||||
} else {
|
||||
analogInputsToReport |= (1 << analogPin);
|
||||
Serial.print(F("Will report analog pin #")); Serial.println(analogPin);
|
||||
}
|
||||
}
|
||||
// TODO: save status to EEPROM here, if changed
|
||||
}
|
||||
|
||||
void reportDigitalCallback(byte port, int value)
|
||||
{
|
||||
if (port < TOTAL_PORTS) {
|
||||
Serial.print(F("Will report 0x")); Serial.print(value, HEX); Serial.print(F(" digital mask on port ")); Serial.println(port);
|
||||
reportPINs[port] = (byte)value;
|
||||
}
|
||||
// do not disable analog reporting on these 8 pins, to allow some
|
||||
// pins used for digital, others analog. Instead, allow both types
|
||||
// of reporting to be enabled, but check if the pin is configured
|
||||
// as analog when sampling the analog inputs. Likewise, while
|
||||
// scanning digital pins, portConfigInputs will mask off values from any
|
||||
// pins configured as analog
|
||||
}
|
||||
|
||||
/*==============================================================================
|
||||
* SYSEX-BASED commands
|
||||
*============================================================================*/
|
||||
|
||||
void sysexCallback(byte command, byte argc, byte *argv)
|
||||
{
|
||||
byte mode;
|
||||
byte slaveAddress;
|
||||
byte slaveRegister;
|
||||
byte data;
|
||||
unsigned int delayTime;
|
||||
|
||||
switch(command) {
|
||||
case I2C_REQUEST:
|
||||
mode = argv[1] & I2C_READ_WRITE_MODE_MASK;
|
||||
if (argv[1] & I2C_10BIT_ADDRESS_MODE_MASK) {
|
||||
//BLE_Firmata.sendString("10-bit addressing mode is not yet supported");
|
||||
Serial.println(F("10-bit addressing mode is not yet supported"));
|
||||
return;
|
||||
}
|
||||
else {
|
||||
slaveAddress = argv[0];
|
||||
}
|
||||
|
||||
switch(mode) {
|
||||
case I2C_WRITE:
|
||||
Wire.beginTransmission(slaveAddress);
|
||||
for (byte i = 2; i < argc; i += 2) {
|
||||
data = argv[i] + (argv[i + 1] << 7);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(data);
|
||||
#else
|
||||
Wire.send(data);
|
||||
#endif
|
||||
}
|
||||
Wire.endTransmission();
|
||||
delayMicroseconds(70);
|
||||
break;
|
||||
case I2C_READ:
|
||||
if (argc == 6) {
|
||||
// a slave register is specified
|
||||
slaveRegister = argv[2] + (argv[3] << 7);
|
||||
data = argv[4] + (argv[5] << 7); // bytes to read
|
||||
readAndReportData(slaveAddress, (int)slaveRegister, data);
|
||||
}
|
||||
else {
|
||||
// a slave register is NOT specified
|
||||
data = argv[2] + (argv[3] << 7); // bytes to read
|
||||
readAndReportData(slaveAddress, (int)REGISTER_NOT_SPECIFIED, data);
|
||||
}
|
||||
break;
|
||||
case I2C_READ_CONTINUOUSLY:
|
||||
if ((queryIndex + 1) >= MAX_QUERIES) {
|
||||
// too many queries, just ignore
|
||||
BLE_Firmata.sendString("too many queries");
|
||||
break;
|
||||
}
|
||||
queryIndex++;
|
||||
query[queryIndex].addr = slaveAddress;
|
||||
query[queryIndex].reg = argv[2] + (argv[3] << 7);
|
||||
query[queryIndex].bytes = argv[4] + (argv[5] << 7);
|
||||
break;
|
||||
case I2C_STOP_READING:
|
||||
byte queryIndexToSkip;
|
||||
// if read continuous mode is enabled for only 1 i2c device, disable
|
||||
// read continuous reporting for that device
|
||||
if (queryIndex <= 0) {
|
||||
queryIndex = -1;
|
||||
} else {
|
||||
// if read continuous mode is enabled for multiple devices,
|
||||
// determine which device to stop reading and remove it's data from
|
||||
// the array, shifiting other array data to fill the space
|
||||
for (byte i = 0; i < queryIndex + 1; i++) {
|
||||
if (query[i].addr = slaveAddress) {
|
||||
queryIndexToSkip = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (byte i = queryIndexToSkip; i<queryIndex + 1; i++) {
|
||||
if (i < MAX_QUERIES) {
|
||||
query[i].addr = query[i+1].addr;
|
||||
query[i].reg = query[i+1].addr;
|
||||
query[i].bytes = query[i+1].bytes;
|
||||
}
|
||||
}
|
||||
queryIndex--;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case I2C_CONFIG:
|
||||
delayTime = (argv[0] + (argv[1] << 7));
|
||||
|
||||
if(delayTime > 0) {
|
||||
i2cReadDelayTime = delayTime;
|
||||
}
|
||||
|
||||
if (!isI2CEnabled) {
|
||||
enableI2CPins();
|
||||
}
|
||||
|
||||
break;
|
||||
case SERVO_CONFIG:
|
||||
if(argc > 4) {
|
||||
// these vars are here for clarity, they'll optimized away by the compiler
|
||||
byte pin = argv[0];
|
||||
int minPulse = argv[1] + (argv[2] << 7);
|
||||
int maxPulse = argv[3] + (argv[4] << 7);
|
||||
|
||||
if (IS_PIN_SERVO(pin)) {
|
||||
if (servos[PIN_TO_SERVO(pin)].attached())
|
||||
servos[PIN_TO_SERVO(pin)].detach();
|
||||
servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin), minPulse, maxPulse);
|
||||
setPinModeCallback(pin, SERVO);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SAMPLING_INTERVAL:
|
||||
if (argc > 1) {
|
||||
samplingInterval = argv[0] + (argv[1] << 7);
|
||||
if (samplingInterval < MINIMUM_SAMPLING_INTERVAL) {
|
||||
samplingInterval = MINIMUM_SAMPLING_INTERVAL;
|
||||
}
|
||||
} else {
|
||||
//BLE_Firmata.sendString("Not enough data");
|
||||
}
|
||||
break;
|
||||
case EXTENDED_ANALOG:
|
||||
if (argc > 1) {
|
||||
int val = argv[1];
|
||||
if (argc > 2) val |= (argv[2] << 7);
|
||||
if (argc > 3) val |= (argv[3] << 14);
|
||||
analogWriteCallback(argv[0], val);
|
||||
}
|
||||
break;
|
||||
case CAPABILITY_QUERY:
|
||||
Serial.write(START_SYSEX);
|
||||
Serial.write(CAPABILITY_RESPONSE);
|
||||
for (byte pin=0; pin < TOTAL_PINS; pin++) {
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
Serial.write((byte)INPUT);
|
||||
Serial.write(1);
|
||||
Serial.write((byte)OUTPUT);
|
||||
Serial.write(1);
|
||||
}
|
||||
if (IS_PIN_ANALOG(pin)) {
|
||||
Serial.write(ANALOG);
|
||||
Serial.write(10);
|
||||
}
|
||||
if (IS_PIN_PWM(pin)) {
|
||||
Serial.write(PWM);
|
||||
Serial.write(8);
|
||||
}
|
||||
if (IS_PIN_SERVO(pin)) {
|
||||
Serial.write(SERVO);
|
||||
Serial.write(14);
|
||||
}
|
||||
if (IS_PIN_I2C(pin)) {
|
||||
Serial.write(I2C);
|
||||
Serial.write(1); // to do: determine appropriate value
|
||||
}
|
||||
Serial.write(127);
|
||||
}
|
||||
Serial.write(END_SYSEX);
|
||||
break;
|
||||
case PIN_STATE_QUERY:
|
||||
if (argc > 0) {
|
||||
byte pin=argv[0];
|
||||
Serial.write(START_SYSEX);
|
||||
Serial.write(PIN_STATE_RESPONSE);
|
||||
Serial.write(pin);
|
||||
if (pin < TOTAL_PINS) {
|
||||
Serial.write((byte)pinConfig[pin]);
|
||||
Serial.write((byte)pinState[pin] & 0x7F);
|
||||
if (pinState[pin] & 0xFF80) Serial.write((byte)(pinState[pin] >> 7) & 0x7F);
|
||||
if (pinState[pin] & 0xC000) Serial.write((byte)(pinState[pin] >> 14) & 0x7F);
|
||||
}
|
||||
Serial.write(END_SYSEX);
|
||||
}
|
||||
break;
|
||||
case ANALOG_MAPPING_QUERY:
|
||||
Serial.write(START_SYSEX);
|
||||
Serial.write(ANALOG_MAPPING_RESPONSE);
|
||||
for (byte pin=0; pin < TOTAL_PINS; pin++) {
|
||||
Serial.write(IS_PIN_ANALOG(pin) ? PIN_TO_ANALOG(pin) : 127);
|
||||
}
|
||||
Serial.write(END_SYSEX);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void enableI2CPins()
|
||||
{
|
||||
byte i;
|
||||
// is there a faster way to do this? would probaby require importing
|
||||
// Arduino.h to get SCL and SDA pins
|
||||
for (i=0; i < TOTAL_PINS; i++) {
|
||||
if(IS_PIN_I2C(i)) {
|
||||
// mark pins as i2c so they are ignore in non i2c data requests
|
||||
setPinModeCallback(i, I2C);
|
||||
}
|
||||
}
|
||||
|
||||
isI2CEnabled = true;
|
||||
|
||||
// is there enough time before the first I2C request to call this here?
|
||||
Wire.begin();
|
||||
}
|
||||
|
||||
/* disable the i2c pins so they can be used for other functions */
|
||||
void disableI2CPins() {
|
||||
isI2CEnabled = false;
|
||||
// disable read continuous mode for all devices
|
||||
queryIndex = -1;
|
||||
// uncomment the following if or when the end() method is added to Wire library
|
||||
// Wire.end();
|
||||
}
|
||||
|
||||
/*==============================================================================
|
||||
* SETUP()
|
||||
*============================================================================*/
|
||||
|
||||
void systemResetCallback()
|
||||
{
|
||||
// initialize a defalt state
|
||||
Serial.println(F("***RESET***"));
|
||||
// TODO: option to load config from EEPROM instead of default
|
||||
if (isI2CEnabled) {
|
||||
disableI2CPins();
|
||||
}
|
||||
for (byte i=0; i < TOTAL_PORTS; i++) {
|
||||
reportPINs[i] = false; // by default, reporting off
|
||||
portConfigInputs[i] = 0; // until activated
|
||||
previousPINs[i] = 0;
|
||||
}
|
||||
// pins with analog capability default to analog input
|
||||
// otherwise, pins default to digital output
|
||||
for (byte i=0; i < TOTAL_PINS; i++) {
|
||||
if (IS_PIN_ANALOG(i)) {
|
||||
// turns off pullup, configures everything
|
||||
setPinModeCallback(i, ANALOG);
|
||||
} else {
|
||||
// sets the output to 0, configures portConfigInputs
|
||||
setPinModeCallback(i, INPUT);
|
||||
}
|
||||
}
|
||||
// by default, do not report any analog inputs
|
||||
analogInputsToReport = 0;
|
||||
|
||||
/* send digital inputs to set the initial state on the host computer,
|
||||
* since once in the loop(), this firmware will only send on change */
|
||||
/*
|
||||
TODO: this can never execute, since no pins default to digital input
|
||||
but it will be needed when/if we support EEPROM stored config
|
||||
for (byte i=0; i < TOTAL_PORTS; i++) {
|
||||
outputPort(i, readPort(i, portConfigInputs[i]), true);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
aci_evt_opcode_t lastBTLEstatus, BTLEstatus;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println(F("Adafruit BTLE Firmata test"));
|
||||
|
||||
BLEserial.begin();
|
||||
|
||||
BTLEstatus = lastBTLEstatus = ACI_EVT_DISCONNECTED;
|
||||
}
|
||||
|
||||
void firmataInit() {
|
||||
Serial.println(F("Init firmata"));
|
||||
//BLE_Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);
|
||||
//Serial.println(F("firmata analog"));
|
||||
BLE_Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
|
||||
//Serial.println(F("firmata digital"));
|
||||
BLE_Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
|
||||
//Serial.println(F("firmata analog report"));
|
||||
BLE_Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
|
||||
//Serial.println(F("firmata digital report"));
|
||||
BLE_Firmata.attach(REPORT_DIGITAL, reportDigitalCallback);
|
||||
//Serial.println(F("firmata pinmode"));
|
||||
BLE_Firmata.attach(SET_PIN_MODE, setPinModeCallback);
|
||||
//Serial.println(F("firmata sysex"));
|
||||
BLE_Firmata.attach(START_SYSEX, sysexCallback);
|
||||
//Serial.println(F("firmata reset"));
|
||||
BLE_Firmata.attach(SYSTEM_RESET, systemResetCallback);
|
||||
|
||||
Serial.println(F("Begin firmata"));
|
||||
BLE_Firmata.begin();
|
||||
systemResetCallback(); // reset to default config
|
||||
}
|
||||
/*==============================================================================
|
||||
* LOOP()
|
||||
*============================================================================*/
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Check the BTLE link, how're we doing?
|
||||
BLEserial.pollACI();
|
||||
// Link status check
|
||||
BTLEstatus = BLEserial.getState();
|
||||
|
||||
// Check if something has changed
|
||||
if (BTLEstatus != lastBTLEstatus) {
|
||||
// print it out!
|
||||
if (BTLEstatus == ACI_EVT_DEVICE_STARTED) {
|
||||
Serial.println(F("* Advertising started"));
|
||||
}
|
||||
if (BTLEstatus == ACI_EVT_CONNECTED) {
|
||||
Serial.println(F("* Connected!"));
|
||||
// initialize Firmata cleanly
|
||||
firmataInit();
|
||||
}
|
||||
if (BTLEstatus == ACI_EVT_DISCONNECTED) {
|
||||
Serial.println(F("* Disconnected or advertising timed out"));
|
||||
}
|
||||
// OK set the last status change to this one
|
||||
lastBTLEstatus = BTLEstatus;
|
||||
}
|
||||
|
||||
// if not connected... bail
|
||||
if (BTLEstatus != ACI_EVT_CONNECTED) {
|
||||
delay(100);
|
||||
return;
|
||||
}
|
||||
|
||||
// For debugging, see if there's data on the serial console, we would forwad it to BTLE
|
||||
if (Serial.available()) {
|
||||
BLEserial.write(Serial.read());
|
||||
}
|
||||
|
||||
// Onto the Firmata main loop
|
||||
|
||||
byte pin, analogPin;
|
||||
|
||||
/* DIGITALREAD - as fast as possible, check for changes and output them to the
|
||||
* BTLE buffer using Serial.print() */
|
||||
checkDigitalInputs();
|
||||
|
||||
/* SERIALREAD - processing incoming messagse as soon as possible, while still
|
||||
* checking digital inputs. */
|
||||
while(BLE_Firmata.available()) {
|
||||
//Serial.println(F("*data available*"));
|
||||
BLE_Firmata.processInput();
|
||||
}
|
||||
/* SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over
|
||||
* 60 bytes. use a timer to sending an event character every 4 ms to
|
||||
* trigger the buffer to dump. */
|
||||
|
||||
// make the sampling interval longer if we have more analog inputs!
|
||||
uint8_t analogreportnums = 0;
|
||||
for(uint8_t a=0; a<8; a++) {
|
||||
if (analogInputsToReport & (1 << a)) {
|
||||
analogreportnums++;
|
||||
}
|
||||
}
|
||||
|
||||
samplingInterval = (uint16_t)MINIMUM_SAMPLE_DELAY + (uint16_t)ANALOG_SAMPLE_DELAY * (1+analogreportnums);
|
||||
|
||||
currentMillis = millis();
|
||||
if (currentMillis - previousMillis > samplingInterval) {
|
||||
previousMillis += samplingInterval;
|
||||
/* ANALOGREAD - do all analogReads() at the configured sampling interval */
|
||||
for(pin=0; pin<TOTAL_PINS; pin++) {
|
||||
if (IS_PIN_ANALOG(pin) && (pinConfig[pin] == ANALOG)) {
|
||||
analogPin = PIN_TO_ANALOG(pin);
|
||||
|
||||
if (analogInputsToReport & (1 << analogPin)) {
|
||||
int currentRead = analogRead(analogPin);
|
||||
|
||||
if ((lastAnalogReads[analogPin] == -1) || (lastAnalogReads[analogPin] != currentRead)) {
|
||||
Serial.print(F("Analog")); Serial.print(analogPin); Serial.print(F(" = ")); Serial.println(currentRead);
|
||||
BLE_Firmata.sendAnalog(analogPin, currentRead);
|
||||
lastAnalogReads[analogPin] = currentRead;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// report i2c data for all device with read continuous mode enabled
|
||||
if (queryIndex > -1) {
|
||||
for (byte i = 0; i < queryIndex + 1; i++) {
|
||||
readAndReportData(query[i].addr, query[i].reg, query[i].bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
62
Projects/libraries/Installed_libs/Adafruit_BLEFirmata/keywords.txt
Executable file
62
Projects/libraries/Installed_libs/Adafruit_BLEFirmata/keywords.txt
Executable file
@@ -0,0 +1,62 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For Firmata
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
Firmata KEYWORD1
|
||||
callbackFunction KEYWORD1
|
||||
systemResetCallbackFunction KEYWORD1
|
||||
stringCallbackFunction KEYWORD1
|
||||
sysexCallbackFunction KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
begin KEYWORD2
|
||||
begin KEYWORD2
|
||||
printVersion KEYWORD2
|
||||
blinkVersion KEYWORD2
|
||||
printFirmwareVersion KEYWORD2
|
||||
setFirmwareVersion KEYWORD2
|
||||
setFirmwareNameAndVersion KEYWORD2
|
||||
available KEYWORD2
|
||||
processInput KEYWORD2
|
||||
sendAnalog KEYWORD2
|
||||
sendDigital KEYWORD2
|
||||
sendDigitalPortPair KEYWORD2
|
||||
sendDigitalPort KEYWORD2
|
||||
sendString KEYWORD2
|
||||
sendString KEYWORD2
|
||||
sendSysex KEYWORD2
|
||||
attach KEYWORD2
|
||||
detach KEYWORD2
|
||||
flush KEYWORD2
|
||||
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
MAX_DATA_BYTES LITERAL1
|
||||
|
||||
DIGITAL_MESSAGE LITERAL1
|
||||
ANALOG_MESSAGE LITERAL1
|
||||
REPORT_ANALOG LITERAL1
|
||||
REPORT_DIGITAL LITERAL1
|
||||
REPORT_VERSION LITERAL1
|
||||
SET_PIN_MODE LITERAL1
|
||||
SYSTEM_RESET LITERAL1
|
||||
|
||||
START_SYSEX LITERAL1
|
||||
END_SYSEX LITERAL1
|
||||
|
||||
PWM LITERAL1
|
||||
|
||||
TOTAL_ANALOG_PINS LITERAL1
|
||||
TOTAL_DIGITAL_PINS LITERAL1
|
||||
TOTAL_PORTS LITERAL1
|
||||
ANALOG_PORT LITERAL1
|
||||
483
Projects/libraries/Installed_libs/Adafruit_BLE_UART/Adafruit_BLE_UART.cpp
Executable file
483
Projects/libraries/Installed_libs/Adafruit_BLE_UART/Adafruit_BLE_UART.cpp
Executable file
@@ -0,0 +1,483 @@
|
||||
/*********************************************************************
|
||||
This is a library for our nRF8001 Bluetooth Low Energy Breakout
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/1697
|
||||
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Kevin Townsend/KTOWN for Adafruit Industries.
|
||||
MIT license, check LICENSE for more information
|
||||
All text above, and the splash screen below must be included in any redistribution
|
||||
*********************************************************************/
|
||||
#include <SPI.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <util/delay.h>
|
||||
#include <stdlib.h>
|
||||
#include <ble_system.h>
|
||||
#include <lib_aci.h>
|
||||
#include <aci_setup.h>
|
||||
#include "uart/services.h"
|
||||
|
||||
#include "Adafruit_BLE_UART.h"
|
||||
|
||||
/* Get the service pipe data created in nRFGo Studio */
|
||||
#ifdef SERVICES_PIPE_TYPE_MAPPING_CONTENT
|
||||
static services_pipe_type_mapping_t
|
||||
services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT;
|
||||
#else
|
||||
#define NUMBER_OF_PIPES 0
|
||||
static services_pipe_type_mapping_t * services_pipe_type_mapping = NULL;
|
||||
#endif
|
||||
|
||||
/* Length of the buffer used to store flash strings temporarily when printing. */
|
||||
#define PRINT_BUFFER_SIZE 20
|
||||
|
||||
/* Store the setup for the nRF8001 in the flash of the AVR to save on RAM */
|
||||
static const hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] PROGMEM = SETUP_MESSAGES_CONTENT;
|
||||
|
||||
static struct aci_state_t aci_state; /* ACI state data */
|
||||
static hal_aci_evt_t aci_data; /* Command buffer */
|
||||
static bool timing_change_done = false;
|
||||
|
||||
// This is the Uart RX buffer, which we manage internally when data is available!
|
||||
#define ADAFRUIT_BLE_UART_RXBUFFER_SIZE 64
|
||||
uint8_t adafruit_ble_rx_buffer[ADAFRUIT_BLE_UART_RXBUFFER_SIZE];
|
||||
volatile uint16_t adafruit_ble_rx_head;
|
||||
volatile uint16_t adafruit_ble_rx_tail;
|
||||
|
||||
|
||||
int8_t HAL_IO_RADIO_RESET, HAL_IO_RADIO_REQN, HAL_IO_RADIO_RDY, HAL_IO_RADIO_IRQ;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
Constructor for the UART service
|
||||
*/
|
||||
/**************************************************************************/
|
||||
// default RX callback!
|
||||
|
||||
void Adafruit_BLE_UART::defaultRX(uint8_t *buffer, uint8_t len)
|
||||
{
|
||||
for(int i=0; i<len; i++)
|
||||
{
|
||||
uint16_t new_head = (uint16_t)(adafruit_ble_rx_head + 1) % ADAFRUIT_BLE_UART_RXBUFFER_SIZE;
|
||||
|
||||
// if we should be storing the received character into the location
|
||||
// just before the tail (meaning that the head would advance to the
|
||||
// current location of the tail), we're about to overflow the buffer
|
||||
// and so we don't write the character or advance the head.
|
||||
if (new_head != adafruit_ble_rx_tail) {
|
||||
adafruit_ble_rx_buffer[adafruit_ble_rx_head] = buffer[i];
|
||||
|
||||
// debug echo print
|
||||
// Serial.print((char)buffer[i]);
|
||||
|
||||
adafruit_ble_rx_head = new_head;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Serial.print("Buffer: ");
|
||||
for(int i=0; i<adafruit_ble_rx_head; i++)
|
||||
{
|
||||
Serial.print(" 0x"); Serial.print((char)adafruit_ble_rx_buffer[i], HEX);
|
||||
}
|
||||
Serial.println();
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/* Stream stuff */
|
||||
|
||||
int Adafruit_BLE_UART::available(void)
|
||||
{
|
||||
return (uint16_t)(ADAFRUIT_BLE_UART_RXBUFFER_SIZE + adafruit_ble_rx_head - adafruit_ble_rx_tail)
|
||||
% ADAFRUIT_BLE_UART_RXBUFFER_SIZE;
|
||||
}
|
||||
|
||||
int Adafruit_BLE_UART::read(void)
|
||||
{
|
||||
// if the head isn't ahead of the tail, we don't have any characters
|
||||
if (adafruit_ble_rx_head == adafruit_ble_rx_tail) {
|
||||
return -1;
|
||||
} else {
|
||||
unsigned char c = adafruit_ble_rx_buffer[adafruit_ble_rx_tail];
|
||||
adafruit_ble_rx_tail ++;
|
||||
adafruit_ble_rx_tail %= ADAFRUIT_BLE_UART_RXBUFFER_SIZE;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
int Adafruit_BLE_UART::peek(void)
|
||||
{
|
||||
if (adafruit_ble_rx_head == adafruit_ble_rx_tail) {
|
||||
return -1;
|
||||
} else {
|
||||
return adafruit_ble_rx_buffer[adafruit_ble_rx_tail];
|
||||
}
|
||||
}
|
||||
|
||||
void Adafruit_BLE_UART::flush(void)
|
||||
{
|
||||
// MEME: KTOWN what do we do here?
|
||||
}
|
||||
|
||||
|
||||
|
||||
//// more callbacks
|
||||
|
||||
void Adafruit_BLE_UART::defaultACICallback(aci_evt_opcode_t event)
|
||||
{
|
||||
currentStatus = event;
|
||||
}
|
||||
|
||||
aci_evt_opcode_t Adafruit_BLE_UART::getState(void) {
|
||||
return currentStatus;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
Constructor for the UART service
|
||||
*/
|
||||
/**************************************************************************/
|
||||
Adafruit_BLE_UART::Adafruit_BLE_UART(int8_t req, int8_t rdy, int8_t rst)
|
||||
{
|
||||
debugMode = true;
|
||||
|
||||
HAL_IO_RADIO_REQN = req;
|
||||
HAL_IO_RADIO_RDY = rdy;
|
||||
HAL_IO_RADIO_RESET = rst;
|
||||
|
||||
rx_event = NULL;
|
||||
aci_event = NULL;
|
||||
|
||||
memset(device_name, 0x00, 8);
|
||||
|
||||
adafruit_ble_rx_head = adafruit_ble_rx_tail = 0;
|
||||
|
||||
currentStatus = ACI_EVT_DISCONNECTED;
|
||||
}
|
||||
|
||||
void Adafruit_BLE_UART::setACIcallback(aci_callback aciEvent) {
|
||||
aci_event = aciEvent;
|
||||
}
|
||||
|
||||
void Adafruit_BLE_UART::setRXcallback(rx_callback rxEvent) {
|
||||
rx_event = rxEvent;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
Transmits data out via the TX characteristic (when available)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
size_t Adafruit_BLE_UART::println(const char * thestr)
|
||||
{
|
||||
uint8_t len = strlen(thestr),
|
||||
written = len ? write((uint8_t *)thestr, len) : 0;
|
||||
if(written == len) written += write((uint8_t *)"\r\n", 2);
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
size_t Adafruit_BLE_UART::print(const char * thestr)
|
||||
{
|
||||
return write((uint8_t *)thestr, strlen(thestr));
|
||||
}
|
||||
|
||||
size_t Adafruit_BLE_UART::print(String thestr)
|
||||
{
|
||||
return write((uint8_t *)thestr.c_str(), thestr.length());
|
||||
}
|
||||
|
||||
size_t Adafruit_BLE_UART::print(int theint)
|
||||
{
|
||||
char message[4*sizeof(int)+1] = {0};
|
||||
itoa(theint, message, 10);
|
||||
return write((uint8_t *)message, strlen(message));
|
||||
}
|
||||
|
||||
size_t Adafruit_BLE_UART::print(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
// Copy bytes from flash string into RAM, then send them a buffer at a time.
|
||||
char buffer[PRINT_BUFFER_SIZE] = {0};
|
||||
const char PROGMEM *p = (const char PROGMEM *)ifsh;
|
||||
size_t written = 0;
|
||||
int i = 0;
|
||||
unsigned char c = pgm_read_byte(p++);
|
||||
// Read data from flash until a null terminator is found.
|
||||
while (c != 0) {
|
||||
// Copy data to RAM and increase buffer index.
|
||||
buffer[i] = c;
|
||||
i++;
|
||||
if (i >= PRINT_BUFFER_SIZE) {
|
||||
// Send buffer when it's full and reset buffer index.
|
||||
written += write((uint8_t *)buffer, PRINT_BUFFER_SIZE);
|
||||
i = 0;
|
||||
}
|
||||
// Grab a new byte from flash.
|
||||
c = pgm_read_byte(p++);
|
||||
}
|
||||
if (i > 0) {
|
||||
// Send any remaining data in the buffer.
|
||||
written += write((uint8_t *)buffer, i);
|
||||
}
|
||||
return written;
|
||||
}
|
||||
|
||||
size_t Adafruit_BLE_UART::write(uint8_t * buffer, uint8_t len)
|
||||
{
|
||||
uint8_t bytesThisPass, sent = 0;
|
||||
|
||||
#ifdef BLE_RW_DEBUG
|
||||
Serial.print(F("\tWriting out to BTLE:"));
|
||||
for (uint8_t i=0; i<len; i++) {
|
||||
Serial.print(F(" 0x")); Serial.print(buffer[i], HEX);
|
||||
}
|
||||
Serial.println();
|
||||
#endif
|
||||
|
||||
while(len) { // Parcelize into chunks
|
||||
bytesThisPass = len;
|
||||
if(bytesThisPass > ACI_PIPE_TX_DATA_MAX_LEN)
|
||||
bytesThisPass = ACI_PIPE_TX_DATA_MAX_LEN;
|
||||
|
||||
if(!lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX))
|
||||
{
|
||||
pollACI();
|
||||
continue;
|
||||
}
|
||||
|
||||
lib_aci_send_data(PIPE_UART_OVER_BTLE_UART_TX_TX, &buffer[sent],
|
||||
bytesThisPass);
|
||||
aci_state.data_credit_available--;
|
||||
|
||||
delay(35); // required delay between sends
|
||||
|
||||
if(!(len -= bytesThisPass)) break;
|
||||
sent += bytesThisPass;
|
||||
}
|
||||
|
||||
return sent;
|
||||
}
|
||||
|
||||
size_t Adafruit_BLE_UART::write(uint8_t buffer)
|
||||
{
|
||||
#ifdef BLE_RW_DEBUG
|
||||
Serial.print(F("\tWriting one byte 0x")); Serial.println(buffer, HEX);
|
||||
#endif
|
||||
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX))
|
||||
{
|
||||
lib_aci_send_data(PIPE_UART_OVER_BTLE_UART_TX_TX, &buffer, 1);
|
||||
aci_state.data_credit_available--;
|
||||
|
||||
delay(35); // required delay between sends
|
||||
return 1;
|
||||
}
|
||||
|
||||
pollACI();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
Update the device name (7 characters or less!)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_BLE_UART::setDeviceName(const char * deviceName)
|
||||
{
|
||||
if (strlen(deviceName) > 7)
|
||||
{
|
||||
/* String too long! */
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(device_name, deviceName, strlen(deviceName));
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
Handles low level ACI events, and passes them up to an application
|
||||
level callback when appropriate
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_BLE_UART::pollACI()
|
||||
{
|
||||
// We enter the if statement only when there is a ACI event available to be processed
|
||||
if (lib_aci_event_get(&aci_state, &aci_data))
|
||||
{
|
||||
aci_evt_t * aci_evt;
|
||||
|
||||
aci_evt = &aci_data.evt;
|
||||
switch(aci_evt->evt_opcode)
|
||||
{
|
||||
/* As soon as you reset the nRF8001 you will get an ACI Device Started Event */
|
||||
case ACI_EVT_DEVICE_STARTED:
|
||||
{
|
||||
aci_state.data_credit_total = aci_evt->params.device_started.credit_available;
|
||||
switch(aci_evt->params.device_started.device_mode)
|
||||
{
|
||||
case ACI_DEVICE_SETUP:
|
||||
/* Device is in setup mode! */
|
||||
if (ACI_STATUS_TRANSACTION_COMPLETE != do_aci_setup(&aci_state))
|
||||
{
|
||||
if (debugMode) {
|
||||
Serial.println(F("Error in ACI Setup"));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_DEVICE_STANDBY:
|
||||
/* Start advertising ... first value is advertising time in seconds, the */
|
||||
/* second value is the advertising interval in 0.625ms units */
|
||||
if (device_name[0] != 0x00)
|
||||
{
|
||||
/* Update the device name */
|
||||
lib_aci_set_local_data(&aci_state, PIPE_GAP_DEVICE_NAME_SET , (uint8_t *)&device_name, strlen(device_name));
|
||||
}
|
||||
lib_aci_connect(adv_timeout, adv_interval);
|
||||
defaultACICallback(ACI_EVT_DEVICE_STARTED);
|
||||
if (aci_event)
|
||||
aci_event(ACI_EVT_DEVICE_STARTED);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_CMD_RSP:
|
||||
/* If an ACI command response event comes with an error -> stop */
|
||||
if (ACI_STATUS_SUCCESS != aci_evt->params.cmd_rsp.cmd_status)
|
||||
{
|
||||
// ACI ReadDynamicData and ACI WriteDynamicData will have status codes of
|
||||
// TRANSACTION_CONTINUE and TRANSACTION_COMPLETE
|
||||
// all other ACI commands will have status code of ACI_STATUS_SUCCESS for a successful command
|
||||
if (debugMode) {
|
||||
Serial.print(F("ACI Command "));
|
||||
Serial.println(aci_evt->params.cmd_rsp.cmd_opcode, HEX);
|
||||
Serial.println(F("Evt Cmd respone: Error. Arduino is in an while(1); loop"));
|
||||
}
|
||||
while (1);
|
||||
}
|
||||
if (ACI_CMD_GET_DEVICE_VERSION == aci_evt->params.cmd_rsp.cmd_opcode)
|
||||
{
|
||||
// Store the version and configuration information of the nRF8001 in the Hardware Revision String Characteristic
|
||||
lib_aci_set_local_data(&aci_state, PIPE_DEVICE_INFORMATION_HARDWARE_REVISION_STRING_SET,
|
||||
(uint8_t *)&(aci_evt->params.cmd_rsp.params.get_device_version), sizeof(aci_evt_cmd_rsp_params_get_device_version_t));
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_CONNECTED:
|
||||
aci_state.data_credit_available = aci_state.data_credit_total;
|
||||
/* Get the device version of the nRF8001 and store it in the Hardware Revision String */
|
||||
lib_aci_device_version();
|
||||
|
||||
defaultACICallback(ACI_EVT_CONNECTED);
|
||||
if (aci_event)
|
||||
aci_event(ACI_EVT_CONNECTED);
|
||||
|
||||
case ACI_EVT_PIPE_STATUS:
|
||||
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX) && (false == timing_change_done))
|
||||
{
|
||||
lib_aci_change_timing_GAP_PPCP(); // change the timing on the link as specified in the nRFgo studio -> nRF8001 conf. -> GAP.
|
||||
// Used to increase or decrease bandwidth
|
||||
timing_change_done = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_TIMING:
|
||||
/* Link connection interval changed */
|
||||
break;
|
||||
|
||||
case ACI_EVT_DISCONNECTED:
|
||||
/* Restart advertising ... first value is advertising time in seconds, the */
|
||||
/* second value is the advertising interval in 0.625ms units */
|
||||
|
||||
defaultACICallback(ACI_EVT_DISCONNECTED);
|
||||
if (aci_event)
|
||||
aci_event(ACI_EVT_DISCONNECTED);
|
||||
|
||||
lib_aci_connect(adv_timeout, adv_interval);
|
||||
|
||||
defaultACICallback(ACI_EVT_DEVICE_STARTED);
|
||||
if (aci_event)
|
||||
aci_event(ACI_EVT_DEVICE_STARTED);
|
||||
break;
|
||||
|
||||
case ACI_EVT_DATA_RECEIVED:
|
||||
defaultRX(aci_evt->params.data_received.rx_data.aci_data, aci_evt->len - 2);
|
||||
if (rx_event)
|
||||
rx_event(aci_evt->params.data_received.rx_data.aci_data, aci_evt->len - 2);
|
||||
break;
|
||||
|
||||
case ACI_EVT_DATA_CREDIT:
|
||||
aci_state.data_credit_available = aci_state.data_credit_available + aci_evt->params.data_credit.credit;
|
||||
break;
|
||||
|
||||
case ACI_EVT_PIPE_ERROR:
|
||||
/* See the appendix in the nRF8001 Product Specication for details on the error codes */
|
||||
if (debugMode) {
|
||||
Serial.print(F("ACI Evt Pipe Error: Pipe #:"));
|
||||
Serial.print(aci_evt->params.pipe_error.pipe_number, DEC);
|
||||
Serial.print(F(" Pipe Error Code: 0x"));
|
||||
Serial.println(aci_evt->params.pipe_error.error_code, HEX);
|
||||
}
|
||||
|
||||
/* Increment the credit available as the data packet was not sent */
|
||||
aci_state.data_credit_available++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serial.println(F("No ACI Events available"));
|
||||
// No event in the ACI Event queue and if there is no event in the ACI command queue the arduino can go to sleep
|
||||
// Arduino can go to sleep now
|
||||
// Wakeup from sleep from the RDYN line
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
Configures the nRF8001 and starts advertising the UART Service
|
||||
|
||||
@param[in] advTimeout
|
||||
The advertising timeout in seconds (0 = infinite advertising)
|
||||
@param[in] advInterval
|
||||
The delay between advertising packets in 0.625ms units
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool Adafruit_BLE_UART::begin(uint16_t advTimeout, uint16_t advInterval)
|
||||
{
|
||||
/* Store the advertising timeout and interval */
|
||||
adv_timeout = advTimeout; /* ToDo: Check range! */
|
||||
adv_interval = advInterval; /* ToDo: Check range! */
|
||||
|
||||
/* Setup the service data from nRFGo Studio (services.h) */
|
||||
if (NULL != services_pipe_type_mapping)
|
||||
{
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
|
||||
}
|
||||
aci_state.aci_setup_info.number_of_pipes = NUMBER_OF_PIPES;
|
||||
aci_state.aci_setup_info.setup_msgs = (hal_aci_data_t*)setup_msgs;
|
||||
aci_state.aci_setup_info.num_setup_msgs = NB_SETUP_MESSAGES;
|
||||
|
||||
/* Pass the service data into the appropriate struct in the ACI */
|
||||
lib_aci_init(&aci_state);
|
||||
|
||||
/* ToDo: Check for chip ID to make sure we're connected! */
|
||||
|
||||
return true;
|
||||
}
|
||||
86
Projects/libraries/Installed_libs/Adafruit_BLE_UART/Adafruit_BLE_UART.h
Executable file
86
Projects/libraries/Installed_libs/Adafruit_BLE_UART/Adafruit_BLE_UART.h
Executable file
@@ -0,0 +1,86 @@
|
||||
/*********************************************************************
|
||||
This is a library for our nRF8001 Bluetooth Low Energy Breakout
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/1697
|
||||
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Kevin Townsend/KTOWN for Adafruit Industries.
|
||||
MIT license, check LICENSE for more information
|
||||
All text above, and the splash screen below must be included in any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ADAFRUIT_BLE_UART_H_
|
||||
#define _ADAFRUIT_BLE_UART_H_
|
||||
|
||||
#include "utility/aci_evts.h"
|
||||
|
||||
#define BLE_RW_DEBUG
|
||||
|
||||
extern "C"
|
||||
{
|
||||
/* Callback prototypes */
|
||||
typedef void (*aci_callback)(aci_evt_opcode_t event);
|
||||
typedef void (*rx_callback) (uint8_t *buffer, uint8_t len);
|
||||
}
|
||||
|
||||
class Adafruit_BLE_UART : public Stream
|
||||
{
|
||||
public:
|
||||
Adafruit_BLE_UART (int8_t req, int8_t rdy, int8_t rst);
|
||||
|
||||
bool begin ( uint16_t advTimeout = 0, uint16_t advInterval = 80 );
|
||||
void pollACI ( void );
|
||||
size_t write ( uint8_t * buffer, uint8_t len );
|
||||
size_t write ( uint8_t buffer);
|
||||
|
||||
size_t println(const char * thestr);
|
||||
size_t print(const char * thestr);
|
||||
size_t print(String thestr);
|
||||
size_t print(int theint);
|
||||
size_t print(const __FlashStringHelper *ifsh);
|
||||
|
||||
void setACIcallback(aci_callback aciEvent = NULL);
|
||||
void setRXcallback(rx_callback rxEvent = NULL);
|
||||
void setDeviceName(const char * deviceName);
|
||||
|
||||
// Stream compatibility
|
||||
int available(void);
|
||||
int read(void);
|
||||
int peek(void);
|
||||
void flush(void);
|
||||
|
||||
aci_evt_opcode_t getState(void);
|
||||
|
||||
private:
|
||||
void defaultACICallback(aci_evt_opcode_t event);
|
||||
void defaultRX(uint8_t *buffer, uint8_t len);
|
||||
|
||||
// callbacks you can set with setCallback function for user extension
|
||||
aci_callback aci_event;
|
||||
rx_callback rx_event;
|
||||
|
||||
bool debugMode;
|
||||
uint16_t adv_timeout;
|
||||
uint16_t adv_interval;
|
||||
char device_name[8];
|
||||
|
||||
aci_evt_opcode_t currentStatus;
|
||||
|
||||
// pins usd
|
||||
int8_t _REQ, _RDY, _RST;
|
||||
};
|
||||
|
||||
#endif
|
||||
48
Projects/libraries/Installed_libs/Adafruit_BLE_UART/README.md
Executable file
48
Projects/libraries/Installed_libs/Adafruit_BLE_UART/README.md
Executable file
@@ -0,0 +1,48 @@
|
||||
# Adafruit_nRF8001 #
|
||||
|
||||
Driver and example code for Adafruit's nRF8001 Bluetooth Low Energy Breakout.
|
||||
|
||||
## PINOUT ##
|
||||
|
||||
The pin locations are defined in **ble_system.h**, the supported systems are defined in **hal_aci_tl.cpp**. The following pinout is used by default for the Arduino Uno:
|
||||
|
||||
* SCK -> Pin 13
|
||||
* MISO -> Pin 12
|
||||
* MOSI -> Pin 11
|
||||
* REQ -> Pin 10
|
||||
* RDY -> Pin 2 (HW interrupt)
|
||||
* ACT -> Not connected
|
||||
* RST -> Pin 9
|
||||
* 3V0 - > Not connected
|
||||
* GND -> GND
|
||||
* VIN -> 5V
|
||||
|
||||
RDY must be on pin 2 since this pin requires a HW interrupt.
|
||||
|
||||
3V0 is an optional pin that exposes the output of the on-board 3.3V regulator. You can use this to supply 3.3V to other peripherals, but normally it will be left unconnected.
|
||||
|
||||
ACT is not currently used in any of the existing examples, and can be left unconnected if necessary.
|
||||
|
||||
# Examples #
|
||||
|
||||
The following examples are included for the Adafruit nRF8001 Breakout
|
||||
|
||||
## UART ##
|
||||
|
||||
This example creates a UART-style bridge between the Arduino and any BLE capable device.
|
||||
|
||||
You can send and receive up to 20 bytes at a time between your BLE-enabled phone or tablet and the Arduino.
|
||||
|
||||
Any data sent to the Arduino will be displayed in the Serial Monitor output, and echo'ed back to the phone or tablet on the mobile device's RX channel.
|
||||
|
||||
This demo creates a custom UART service, with one characteristic for TX and one for RX using the following UUIDs:
|
||||
|
||||
* 6E400001-B5A3-F393-E0A9-E50E24DCCA9E for the Service
|
||||
* 6E400002-B5A3-F393-E0A9-E50E24DCCA9E for the TX Characteristic (Property = Notify)
|
||||
* 6E400003-B5A3-F393-E0A9-E50E24DCCA9E for the RX Characteristic (Property = Write without response)
|
||||
|
||||
You can test the UART service with the free nRF UART apps from Nordic Semiconductors, available for both iOS and Android:
|
||||
|
||||
* Compatible iOS devices: https://itunes.apple.com/us/app/nrf-uart/id614594903?mt=8
|
||||
* Compatible Android 4.3 and higher devices: https://play.google.com/store/apps/details?id=com.nordicsemi.nrfUARTv2
|
||||
* Compatible pre Android 4.3 Samsung devices (uses a proprietary Samsung BLE stack): https://play.google.com/store/apps/details?id=com.nordicsemi.nrfUART
|
||||
@@ -0,0 +1,100 @@
|
||||
/*********************************************************************
|
||||
This is an example for our nRF8001 Bluetooth Low Energy Breakout
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/1697
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Kevin Townsend/KTOWN for Adafruit Industries.
|
||||
MIT license, check LICENSE for more information
|
||||
All text above, and the splash screen below must be included in any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
// This version uses call-backs on the event and RX so there's no data handling in the main loop!
|
||||
|
||||
#include <SPI.h>
|
||||
#include "Adafruit_BLE_UART.h"
|
||||
|
||||
#define ADAFRUITBLE_REQ 10
|
||||
#define ADAFRUITBLE_RDY 2
|
||||
#define ADAFRUITBLE_RST 9
|
||||
|
||||
Adafruit_BLE_UART uart = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
This function is called whenever select ACI events happen
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void aciCallback(aci_evt_opcode_t event)
|
||||
{
|
||||
switch(event)
|
||||
{
|
||||
case ACI_EVT_DEVICE_STARTED:
|
||||
Serial.println(F("Advertising started"));
|
||||
break;
|
||||
case ACI_EVT_CONNECTED:
|
||||
Serial.println(F("Connected!"));
|
||||
break;
|
||||
case ACI_EVT_DISCONNECTED:
|
||||
Serial.println(F("Disconnected or advertising timed out"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
This function is called whenever data arrives on the RX channel
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void rxCallback(uint8_t *buffer, uint8_t len)
|
||||
{
|
||||
Serial.print(F("Received "));
|
||||
Serial.print(len);
|
||||
Serial.print(F(" bytes: "));
|
||||
for(int i=0; i<len; i++)
|
||||
Serial.print((char)buffer[i]);
|
||||
|
||||
Serial.print(F(" ["));
|
||||
|
||||
for(int i=0; i<len; i++)
|
||||
{
|
||||
Serial.print(" 0x"); Serial.print((char)buffer[i], HEX);
|
||||
}
|
||||
Serial.println(F(" ]"));
|
||||
|
||||
/* Echo the same data back! */
|
||||
uart.write(buffer, len);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
Configure the Arduino and start advertising with the radio
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(9600);
|
||||
while(!Serial); // Leonardo/Micro should wait for serial init
|
||||
Serial.println(F("Adafruit Bluefruit Low Energy nRF8001 Callback Echo demo"));
|
||||
|
||||
uart.setRXcallback(rxCallback);
|
||||
uart.setACIcallback(aciCallback);
|
||||
// uart.setDeviceName("NEWNAME"); /* 7 characters max! */
|
||||
uart.begin();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
Constantly checks for new events on the nRF8001
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void loop()
|
||||
{
|
||||
uart.pollACI();
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*********************************************************************
|
||||
This is an example for our nRF8001 Bluetooth Low Energy Breakout
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/1697
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Kevin Townsend/KTOWN for Adafruit Industries.
|
||||
MIT license, check LICENSE for more information
|
||||
All text above, and the splash screen below must be included in any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
// This version uses the internal data queing so you can treat it like Serial (kinda)!
|
||||
|
||||
#include <SPI.h>
|
||||
#include "Adafruit_BLE_UART.h"
|
||||
|
||||
// Connect CLK/MISO/MOSI to hardware SPI
|
||||
// e.g. On UNO & compatible: CLK = 13, MISO = 12, MOSI = 11
|
||||
#define ADAFRUITBLE_REQ 10
|
||||
#define ADAFRUITBLE_RDY 2 // This should be an interrupt pin, on Uno thats #2 or #3
|
||||
#define ADAFRUITBLE_RST 9
|
||||
|
||||
Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
Configure the Arduino and start advertising with the radio
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(9600);
|
||||
while(!Serial); // Leonardo/Micro should wait for serial init
|
||||
Serial.println(F("Adafruit Bluefruit Low Energy nRF8001 Print echo demo"));
|
||||
|
||||
// BTLEserial.setDeviceName("NEWNAME"); /* 7 characters max! */
|
||||
|
||||
BTLEserial.begin();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
Constantly checks for new events on the nRF8001
|
||||
*/
|
||||
/**************************************************************************/
|
||||
aci_evt_opcode_t laststatus = ACI_EVT_DISCONNECTED;
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Tell the nRF8001 to do whatever it should be working on.
|
||||
BTLEserial.pollACI();
|
||||
|
||||
// Ask what is our current status
|
||||
aci_evt_opcode_t status = BTLEserial.getState();
|
||||
// If the status changed....
|
||||
if (status != laststatus) {
|
||||
// print it out!
|
||||
if (status == ACI_EVT_DEVICE_STARTED) {
|
||||
Serial.println(F("* Advertising started"));
|
||||
}
|
||||
if (status == ACI_EVT_CONNECTED) {
|
||||
Serial.println(F("* Connected!"));
|
||||
}
|
||||
if (status == ACI_EVT_DISCONNECTED) {
|
||||
Serial.println(F("* Disconnected or advertising timed out"));
|
||||
}
|
||||
// OK set the last status change to this one
|
||||
laststatus = status;
|
||||
}
|
||||
|
||||
if (status == ACI_EVT_CONNECTED) {
|
||||
// Lets see if there's any data for us!
|
||||
if (BTLEserial.available()) {
|
||||
Serial.print("* "); Serial.print(BTLEserial.available()); Serial.println(F(" bytes available from BTLE"));
|
||||
}
|
||||
// OK while we still have something to read, get a character and print it out
|
||||
while (BTLEserial.available()) {
|
||||
char c = BTLEserial.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
|
||||
// Next up, see if we have any data to get from the Serial console
|
||||
|
||||
if (Serial.available()) {
|
||||
// Read a line from Serial
|
||||
Serial.setTimeout(100); // 100 millisecond timeout
|
||||
String s = Serial.readString();
|
||||
|
||||
// We need to convert the line to bytes, no more than 20 at this time
|
||||
uint8_t sendbuffer[20];
|
||||
s.getBytes(sendbuffer, 20);
|
||||
char sendbuffersize = min(20, s.length());
|
||||
|
||||
Serial.print(F("\n* Sending -> \"")); Serial.print((char *)sendbuffer); Serial.println("\"");
|
||||
|
||||
// write the data
|
||||
BTLEserial.write(sendbuffer, sendbuffersize);
|
||||
}
|
||||
}
|
||||
}
|
||||
608
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/aci.h
Executable file
608
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/aci.h
Executable file
@@ -0,0 +1,608 @@
|
||||
/* Copyright (c) 2010 Nordic Semiconductor. All Rights Reserved.
|
||||
*
|
||||
* The information contained herein is property of Nordic Semiconductor ASA.
|
||||
* Terms and conditions of usage are described in detail in NORDIC
|
||||
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
|
||||
*
|
||||
* Licensees are granted free, non-transferable use of the information. NO
|
||||
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
|
||||
* the file.
|
||||
*
|
||||
* $LastChangedRevision$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @defgroup aci aci
|
||||
* @{
|
||||
* @ingroup lib
|
||||
*
|
||||
* @brief Definitions for the ACI (Application Control Interface)
|
||||
* @remarks
|
||||
*
|
||||
* Flow control from application mcu to nRF8001
|
||||
*
|
||||
* Data flow control:
|
||||
* The flow control is credit based and the credit is initally given using the "device started" event.
|
||||
* A credit of more than 1 is given to the application mcu.
|
||||
* These credits are used only after the "ACI Connected Event" is sent to the application mcu.
|
||||
*
|
||||
* every send_data that is used decrements the credit available by 1. This is to be tracked by the application mcu.
|
||||
* When the credit available reaches 0, the application mcu shall not send any more send_data.
|
||||
* Credit is returned using the "credit event", this returned credit can then be used to send more send_data.
|
||||
* This flow control is not necessary and not available for Broadcast.
|
||||
* The entire credit available with the external mcu expires when a "disconnected" event arrives.
|
||||
*
|
||||
* Command flow control:
|
||||
* When a command is sent over the ACI, the next command shall not be sent until after a response
|
||||
* for the command sent has arrived.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ACI_H__
|
||||
#define ACI_H__
|
||||
|
||||
/**
|
||||
* @def ACI_VERSION
|
||||
* @brief Current ACI protocol version. 0 means a device that is not yet released.
|
||||
* A numer greater than 0 refers to a specific ACI version documented and released.
|
||||
* The ACI consists of the ACI commands, ACI events and error codes.
|
||||
*/
|
||||
#define ACI_VERSION (0x02)
|
||||
/**
|
||||
* @def BTLE_DEVICE_ADDRESS_SIZE
|
||||
* @brief Size in bytes of a Bluetooth Address
|
||||
*/
|
||||
#define BTLE_DEVICE_ADDRESS_SIZE (6)
|
||||
/**
|
||||
* @def ACI_PACKET_MAX_LEN
|
||||
* @brief Maximum length in bytes of a full ACI packet, including length prefix, opcode and payload
|
||||
*/
|
||||
#define ACI_PACKET_MAX_LEN (32)
|
||||
/**
|
||||
* @def ACI_ECHO_DATA_MAX_LEN
|
||||
* @brief Maximum length in bytes of the echo data portion
|
||||
*/
|
||||
#define ACI_ECHO_DATA_MAX_LEN (ACI_PACKET_MAX_LEN - 3)
|
||||
/**
|
||||
* @def ACI_DEVICE_MAX_PIPES
|
||||
* @brief Maximum number of ACI pipes
|
||||
*/
|
||||
#define ACI_DEVICE_MAX_PIPES (62)
|
||||
/**
|
||||
* @def ACI_PIPE_TX_DATA_MAX_LEN
|
||||
* @brief Maximum length in bytes of a transmission data pipe packet
|
||||
*/
|
||||
#define ACI_PIPE_TX_DATA_MAX_LEN (20)
|
||||
/**
|
||||
* @def ACI_PIPE_RX_DATA_MAX_LEN
|
||||
* @brief Maximum length in bytes of a reception data pipe packet
|
||||
*/
|
||||
#define ACI_PIPE_RX_DATA_MAX_LEN (22)
|
||||
/**
|
||||
* @def ACI_GAP_DEVNAME_MAX_LEN
|
||||
* @brief Maximum length in bytes of the GAP device name
|
||||
*/
|
||||
#define ACI_GAP_DEVNAME_MAX_LEN (20)
|
||||
/**
|
||||
* @def ACI_AD_PACKET_MAX_LEN
|
||||
* @brief Maximum length in bytes of an AD packet
|
||||
*/
|
||||
#define ACI_AD_PACKET_MAX_LEN (31)
|
||||
/**
|
||||
* @def ACI_AD_PACKET_MAX_USER_LEN
|
||||
* @brief Maximum usable length in bytes of an AD packet
|
||||
*/
|
||||
#define ACI_AD_PACKET_MAX_USER_LEN (31 - 3)
|
||||
/**
|
||||
* @def ACI_PIPE_INVALID
|
||||
* @brief Invalid pipe number
|
||||
*/
|
||||
#define ACI_PIPE_INVALID (0xFF)
|
||||
|
||||
/**
|
||||
* @enum aci_pipe_store_t
|
||||
* @brief Storage type identifiers: local and remote
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACI_STORE_INVALID = 0x0,
|
||||
ACI_STORE_LOCAL= 0x01,
|
||||
ACI_STORE_REMOTE= 0x02
|
||||
} aci_pipe_store_t;
|
||||
|
||||
/**
|
||||
* @enum aci_pipe_type_t
|
||||
* @brief Pipe types
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACI_TX_BROADCAST = 0x0001,
|
||||
ACI_TX = 0x0002,
|
||||
ACI_TX_ACK = 0x0004,
|
||||
ACI_RX = 0x0008,
|
||||
ACI_RX_ACK = 0x0010,
|
||||
ACI_TX_REQ = 0x0020,
|
||||
ACI_RX_REQ = 0x0040,
|
||||
ACI_SET = 0x0080,
|
||||
ACI_TX_SIGN = 0x0100,
|
||||
ACI_RX_SIGN = 0x0200,
|
||||
ACI_RX_ACK_AUTO = 0x0400
|
||||
} aci_pipe_type_t;
|
||||
|
||||
/**
|
||||
* @enum aci_bd_addr_type_t
|
||||
* @brief Bluetooth Address types
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACI_BD_ADDR_TYPE_INVALID = 0x00,
|
||||
ACI_BD_ADDR_TYPE_PUBLIC = 0x01,
|
||||
ACI_BD_ADDR_TYPE_RANDOM_STATIC = 0x02,
|
||||
ACI_BD_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE = 0x03,
|
||||
ACI_BD_ADDR_TYPE_RANDOM_PRIVATE_UNRESOLVABLE = 0x04
|
||||
} aci_bd_addr_type_t;
|
||||
|
||||
/**
|
||||
* @enum aci_device_output_power_t
|
||||
* @brief Radio output power levels
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACI_DEVICE_OUTPUT_POWER_MINUS_18DBM = 0x00, /**< Output power set to -18dBm */
|
||||
ACI_DEVICE_OUTPUT_POWER_MINUS_12DBM = 0x01, /**< Output power set to -12dBm */
|
||||
ACI_DEVICE_OUTPUT_POWER_MINUS_6DBM = 0x02, /**< Output power set to -6dBm */
|
||||
ACI_DEVICE_OUTPUT_POWER_0DBM = 0x03 /**< Output power set to 0dBm - DEFAULT*/
|
||||
} aci_device_output_power_t;
|
||||
|
||||
/**
|
||||
* @enum aci_device_operation_mode_t
|
||||
* @brief Device operation modes
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACI_DEVICE_INVALID =0x00,
|
||||
ACI_DEVICE_TEST =0x01,
|
||||
ACI_DEVICE_SETUP =0x02,
|
||||
ACI_DEVICE_STANDBY =0x03,
|
||||
ACI_DEVICE_SLEEP =0x04
|
||||
} aci_device_operation_mode_t;
|
||||
|
||||
/**
|
||||
* @enum aci_disconnect_reason_t
|
||||
* @brief Reason enumeration for ACI_CMD_DISCONNECT
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACI_REASON_TERMINATE =0x01, /**< Use this to disconnect (does a terminate request), you need to wait for the "disconnected" event */
|
||||
ACI_REASON_BAD_TIMING =0x02 /*<Use this to disconnect and inform the peer, that the timing on the link is not acceptable for the device, you need to wait for the "disconnected" event */
|
||||
} aci_disconnect_reason_t;
|
||||
|
||||
/**
|
||||
* @enum aci_test_mode_change_t
|
||||
* @brief Device test mode control
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACI_TEST_MODE_DTM_UART = 0x01,
|
||||
ACI_TEST_MODE_DTM_ACI = 0x02,
|
||||
ACI_TEST_MODE_EXIT = 0xFF
|
||||
|
||||
} aci_test_mode_change_t;
|
||||
|
||||
/**
|
||||
* @enum aci_permissions_t
|
||||
* @brief Data store permissions
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACI_PERMISSIONS_NONE =0x00,
|
||||
ACI_PERMISSIONS_LINK_AUTHENTICATED =0x01
|
||||
} aci_permissions_t;
|
||||
|
||||
/**
|
||||
* @def ACI_VS_UUID_128_MAX_COUNT
|
||||
* @brief Maximum number of 128-bit Vendor Specific
|
||||
* UUIDs that can be set
|
||||
*/
|
||||
#define ACI_VS_UUID_128_MAX_COUNT 64 /** #0 reserved for invalid, #1 reservered for BT SIG and a maximum of 1024 bytes (16*64) */
|
||||
|
||||
/**
|
||||
* @struct aci_ll_conn_params_t
|
||||
* @brief Link Layer Connection Parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t min_conn_interval; /**< Minimum connection interval requested from peer */
|
||||
#define ACI_PPCP_MIN_CONN_INTVL_NONE 0xFFFF
|
||||
#define ACI_PPCP_MIN_CONN_INTVL_MIN 0x0006
|
||||
#define ACI_PPCP_MIN_CONN_INTVL_MAX 0x0C80
|
||||
uint16_t max_conn_interval; /**< Maximum connection interval requested from peer */
|
||||
#define ACI_PPCP_MAX_CONN_INTVL_NONE 0xFFFF
|
||||
#define ACI_PPCP_MAX_CONN_INTVL_MIN 0x0006
|
||||
#define ACI_PPCP_MAX_CONN_INTVL_MAX 0x0C80
|
||||
uint16_t slave_latency; /**< Connection interval latency requested from peer */
|
||||
#define ACI_PPCP_SLAVE_LATENCY_MAX 0x03E8
|
||||
uint16_t timeout_mult; /**< Link supervisor timeout multiplier requested from peer */
|
||||
#define ACI_PPCP_TIMEOUT_MULT_NONE 0xFFFF
|
||||
#define ACI_PPCP_TIMEOUT_MULT_MIN 0x000A
|
||||
#define ACI_PPCP_TIMEOUT_MULT_MAX 0x0C80
|
||||
} aci_ll_conn_params_t;
|
||||
|
||||
/**
|
||||
* @def aci_gap_ppcp_t
|
||||
* @brief GAP Peripheral Preferred Connection Parameters
|
||||
*/
|
||||
#define aci_gap_ppcp_t aci_ll_conn_params_t
|
||||
|
||||
/**
|
||||
* @def ACI_AD_LOC_SVCUUID_16_MAX_COUNT
|
||||
* @brief Maximum number of 16-bit UUIDs that can
|
||||
* be inserted in the Services tag of AD
|
||||
*/
|
||||
#define ACI_AD_LOC_SVCUUID_16_MAX_COUNT 5
|
||||
|
||||
/**
|
||||
* @def ACI_AD_LOC_SVCUUID_128_MAX_COUNT
|
||||
* @brief Maximum number of 128-bit UUIDs that can
|
||||
* be inserted in the Services tag of AD
|
||||
*/
|
||||
#define ACI_AD_LOC_SVCUUID_128_MAX_COUNT 1
|
||||
|
||||
/**
|
||||
* @def ACI_AD_SOL_SVCUUID_16_MAX_COUNT
|
||||
* @brief Maximum number of UUIDs that can
|
||||
* be inserted in the Solicited Services tag of AD
|
||||
*/
|
||||
#define ACI_AD_SOL_SVCUUID_16_MAX_COUNT 5
|
||||
|
||||
/**
|
||||
* @def ACI_AD_SOL_SVCUUID_128_MAX_COUNT
|
||||
* @brief Maximum number of UUIDs that can
|
||||
* be inserted in the Solicited Services tag of AD
|
||||
*/
|
||||
#define ACI_AD_SOL_SVCUUID_128_MAX_COUNT 1
|
||||
|
||||
/**
|
||||
* @def ACI_SEC_ENCKEY_SIZE_MIN
|
||||
* @brief Minimum encryption key size
|
||||
*/
|
||||
#define ACI_SEC_ENCKEY_SIZE_MIN 7
|
||||
/**
|
||||
* @def ACI_SEC_ENCKEY_SIZE_MAX
|
||||
* @brief Maximum encryption key size
|
||||
*/
|
||||
#define ACI_SEC_ENCKEY_SIZE_MAX 16
|
||||
/**
|
||||
* @def ACI_CUSTOM_AD_TYPE_MAX_COUNT
|
||||
* @brief Maximum number of custom ad types
|
||||
*/
|
||||
#define ACI_CUSTOM_AD_TYPE_MAX_COUNT 8
|
||||
/**
|
||||
* @def ACI_CUSTOM_AD_TYPE_MAX_DATA_LENGTH
|
||||
* @brief Maximum custom ad type data size
|
||||
*/
|
||||
#define ACI_CUSTOM_AD_TYPE_MAX_DATA_LENGTH 20
|
||||
|
||||
/**
|
||||
* @struct aci_tx_data_t
|
||||
* @brief Generic ACI transmit data structure
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t pipe_number;
|
||||
uint8_t aci_data[ACI_PIPE_TX_DATA_MAX_LEN];
|
||||
} aci_tx_data_t;
|
||||
|
||||
/**
|
||||
* @struct aci_rx_data_t
|
||||
* @brief Generic ACI receive data structure
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t pipe_number;
|
||||
uint8_t aci_data[ACI_PIPE_RX_DATA_MAX_LEN];
|
||||
} aci_rx_data_t;
|
||||
|
||||
/**
|
||||
* @enum aci_hw_error_t
|
||||
* @brief Hardware Error codes
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACI_HW_ERROR_NONE = 0x00,
|
||||
ACI_HW_ERROR_FATAL = 0x01
|
||||
} aci_hw_error_t;
|
||||
|
||||
/**
|
||||
* @enum aci_clock_accuracy_t
|
||||
* @brief Bluetooth Low Energy Clock Accuracy
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACI_CLOCK_ACCURACY_500_PPM = 0x00,
|
||||
ACI_CLOCK_ACCURACY_250_PPM = 0x01,
|
||||
ACI_CLOCK_ACCURACY_150_PPM = 0x02,
|
||||
ACI_CLOCK_ACCURACY_100_PPM = 0x03,
|
||||
ACI_CLOCK_ACCURACY_75_PPM = 0x04,
|
||||
ACI_CLOCK_ACCURACY_50_PPM = 0x05,
|
||||
ACI_CLOCK_ACCURACY_30_PPM = 0x06,
|
||||
ACI_CLOCK_ACCURACY_20_PPM = 0x07
|
||||
} aci_clock_accuracy_t;
|
||||
|
||||
/**
|
||||
* @enum aci_app_latency_mode_t
|
||||
* @brief Application latency modes
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACI_APP_LATENCY_DISABLE = 0,
|
||||
ACI_APP_LATENCY_ENABLE = 1
|
||||
} aci_app_latency_mode_t;
|
||||
|
||||
/**
|
||||
* @enum gatt_format_t
|
||||
* @brief GATT format definitions
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACI_GATT_FORMAT_NONE = 0x00, /**< No characteristic format available */
|
||||
ACI_GATT_FORMAT_BOOLEAN = 0x01, /**< Not Supported */
|
||||
ACI_GATT_FORMAT_2BIT = 0x02, /**< Not Supported */
|
||||
ACI_GATT_FORMAT_NIBBLE = 0x03, /**< Not Supported */
|
||||
ACI_GATT_FORMAT_UINT8 = 0x04,
|
||||
ACI_GATT_FORMAT_UINT12 = 0x05,
|
||||
ACI_GATT_FORMAT_UINT16 = 0x06,
|
||||
ACI_GATT_FORMAT_UINT24 = 0x07,
|
||||
ACI_GATT_FORMAT_UINT32 = 0x08,
|
||||
ACI_GATT_FORMAT_UINT48 = 0x09,
|
||||
ACI_GATT_FORMAT_UINT64 = 0x0A,
|
||||
ACI_GATT_FORMAT_UINT128 = 0x0B,
|
||||
ACI_GATT_FORMAT_SINT8 = 0x0C,
|
||||
ACI_GATT_FORMAT_SINT12 = 0x0D,
|
||||
ACI_GATT_FORMAT_SINT16 = 0x0E,
|
||||
ACI_GATT_FORMAT_SINT24 = 0x0F,
|
||||
ACI_GATT_FORMAT_SINT32 = 0x10,
|
||||
ACI_GATT_FORMAT_SINT48 = 0x11,
|
||||
ACI_GATT_FORMAT_SINT64 = 0x12,
|
||||
ACI_GATT_FORMAT_SINT128 = 0x13,
|
||||
ACI_GATT_FORMAT_FLOAT32 = 0x14,
|
||||
ACI_GATT_FORMAT_FLOAT64 = 0x15,
|
||||
ACI_GATT_FORMAT_SFLOAT = 0x16,
|
||||
ACI_GATT_FORMAT_FLOAT = 0x17,
|
||||
ACI_GATT_FORMAT_DUINT16 = 0x18,
|
||||
ACI_GATT_FORMAT_UTF8S = 0x19,
|
||||
ACI_GATT_FORMAT_UTF16S = 0x1A,
|
||||
ACI_GATT_FORMAT_STRUCT = 0x1B
|
||||
} aci_gatt_format_t;
|
||||
|
||||
/**
|
||||
* @brief GATT Bluetooth namespace
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACI_GATT_NAMESPACE_INVALID = 0x00,
|
||||
ACI_GATT_NAMESPACE_BTSIG = 0x01 /**< Bluetooth SIG */
|
||||
} aci_gatt_namespace_t;
|
||||
|
||||
/**
|
||||
* @brief Security key types
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACI_KEY_TYPE_INVALID = 0x00,
|
||||
ACI_KEY_TYPE_PASSKEY = 0x01
|
||||
} aci_key_type_t;
|
||||
|
||||
/**
|
||||
* @enum aci_bond_status_code_t
|
||||
* @brief Bond status code
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/**
|
||||
* Bonding succeeded
|
||||
*/
|
||||
ACI_BOND_STATUS_SUCCESS = 0x00,
|
||||
/**
|
||||
* Bonding failed
|
||||
*/
|
||||
ACI_BOND_STATUS_FAILED = 0x01,
|
||||
/**
|
||||
* Bonding error: Timeout can occur when link termination is unexpected or did not get connected OR SMP timer expired
|
||||
*/
|
||||
ACI_BOND_STATUS_FAILED_TIMED_OUT = 0x02,
|
||||
/**
|
||||
* Bonding error: Passkey entry failed
|
||||
*/
|
||||
ACI_BOND_STATUS_FAILED_PASSKEY_ENTRY_FAILED = 0x81,
|
||||
/**
|
||||
* Bonding error: OOB unavailable
|
||||
*/
|
||||
ACI_BOND_STATUS_FAILED_OOB_UNAVAILABLE = 0x82,
|
||||
/**
|
||||
* Bonding error: Authentication request failed
|
||||
*/
|
||||
ACI_BOND_STATUS_FAILED_AUTHENTICATION_REQ = 0x83,
|
||||
/**
|
||||
* Bonding error: Confirm value failed
|
||||
*/
|
||||
ACI_BOND_STATUS_FAILED_CONFIRM_VALUE = 0x84,
|
||||
/**
|
||||
* Bonding error: Pairing unsupported
|
||||
*/
|
||||
ACI_BOND_STATUS_FAILED_PAIRING_UNSUPPORTED = 0x85,
|
||||
/**
|
||||
* Bonding error: Invalid encryption key size
|
||||
*/
|
||||
ACI_BOND_STATUS_FAILED_ENCRYPTION_KEY_SIZE = 0x86,
|
||||
/**
|
||||
* Bonding error: Unsupported SMP command
|
||||
*/
|
||||
ACI_BOND_STATUS_FAILED_SMP_CMD_UNSUPPORTED = 0x87,
|
||||
/**
|
||||
* Bonding error: Unspecified reason
|
||||
*/
|
||||
ACI_BOND_STATUS_FAILED_UNSPECIFIED_REASON = 0x88,
|
||||
/**
|
||||
* Bonding error: Too many attempts
|
||||
*/
|
||||
ACI_BOND_STATUS_FAILED_REPEATED_ATTEMPTS = 0x89,
|
||||
/**
|
||||
* Bonding error: Invalid parameters
|
||||
*/
|
||||
ACI_BOND_STATUS_FAILED_INVALID_PARAMETERS = 0x8A
|
||||
|
||||
} aci_bond_status_code_t;
|
||||
|
||||
/**
|
||||
* @enum aci_bond_status_source_t
|
||||
* @brief Source of a bond status code
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACI_BOND_STATUS_SOURCE_INVALID = 0x00,
|
||||
ACI_BOND_STATUS_SOURCE_LOCAL = 0x01,
|
||||
ACI_BOND_STATUS_SOURCE_REMOTE = 0x02
|
||||
|
||||
} aci_bond_status_source_t;
|
||||
|
||||
/**
|
||||
* @enum aci_status_code_t
|
||||
* @brief ACI status codes
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/**
|
||||
* Success
|
||||
*/
|
||||
ACI_STATUS_SUCCESS = 0x00,
|
||||
/**
|
||||
* Transaction continuation status
|
||||
*/
|
||||
ACI_STATUS_TRANSACTION_CONTINUE = 0x01,
|
||||
/**
|
||||
* Transaction completed
|
||||
*/
|
||||
ACI_STATUS_TRANSACTION_COMPLETE = 0x02,
|
||||
/**
|
||||
* Extended status, further checks needed
|
||||
*/
|
||||
ACI_STATUS_EXTENDED = 0x03,
|
||||
/**
|
||||
* Unknown error.
|
||||
*/
|
||||
ACI_STATUS_ERROR_UNKNOWN = 0x80,
|
||||
/**
|
||||
* Internal error.
|
||||
*/
|
||||
ACI_STATUS_ERROR_INTERNAL = 0x81,
|
||||
/**
|
||||
* Unknown command
|
||||
*/
|
||||
ACI_STATUS_ERROR_CMD_UNKNOWN = 0x82,
|
||||
/**
|
||||
* Command invalid in the current device state
|
||||
*/
|
||||
ACI_STATUS_ERROR_DEVICE_STATE_INVALID = 0x83,
|
||||
/**
|
||||
* Invalid length
|
||||
*/
|
||||
ACI_STATUS_ERROR_INVALID_LENGTH = 0x84,
|
||||
/**
|
||||
* Invalid input parameters
|
||||
*/
|
||||
ACI_STATUS_ERROR_INVALID_PARAMETER = 0x85,
|
||||
/**
|
||||
* Busy
|
||||
*/
|
||||
ACI_STATUS_ERROR_BUSY = 0x86,
|
||||
/**
|
||||
* Invalid data format or contents
|
||||
*/
|
||||
ACI_STATUS_ERROR_INVALID_DATA = 0x87,
|
||||
/**
|
||||
* CRC mismatch
|
||||
*/
|
||||
ACI_STATUS_ERROR_CRC_MISMATCH = 0x88,
|
||||
/**
|
||||
* Unsupported setup format
|
||||
*/
|
||||
ACI_STATUS_ERROR_UNSUPPORTED_SETUP_FORMAT = 0x89,
|
||||
/**
|
||||
* Invalid sequence number during a write dynamic data sequence
|
||||
*/
|
||||
ACI_STATUS_ERROR_INVALID_SEQ_NO = 0x8A,
|
||||
/**
|
||||
* Setup data is locked and cannot be modified
|
||||
*/
|
||||
ACI_STATUS_ERROR_SETUP_LOCKED = 0x8B,
|
||||
/**
|
||||
* Setup error due to lock verification failure
|
||||
*/
|
||||
ACI_STATUS_ERROR_LOCK_FAILED = 0x8C,
|
||||
/**
|
||||
* Bond required: Local Pipes need bonded/trusted peer
|
||||
*/
|
||||
ACI_STATUS_ERROR_BOND_REQUIRED = 0x8D,
|
||||
/**
|
||||
* Command rejected as a transaction is still pending
|
||||
*/
|
||||
ACI_STATUS_ERROR_REJECTED = 0x8E,
|
||||
/**
|
||||
* Pipe Error Event : Data size exceeds size specified for pipe : Transmit failed
|
||||
*/
|
||||
ACI_STATUS_ERROR_DATA_SIZE = 0x8F,
|
||||
/**
|
||||
* Pipe Error Event : Invalid pipe
|
||||
*/
|
||||
ACI_STATUS_ERROR_PIPE_INVALID = 0x90,
|
||||
/**
|
||||
* Pipe Error Event : Credit not available
|
||||
*/
|
||||
ACI_STATUS_ERROR_CREDIT_NOT_AVAILABLE = 0x91,
|
||||
/**
|
||||
* Pipe Error Event : Peer device has sent an error on an pipe operation on the remote characteristic
|
||||
*/
|
||||
ACI_STATUS_ERROR_PEER_ATT_ERROR = 0x92,
|
||||
/**
|
||||
* Connection was not established before the BTLE advertising was stopped
|
||||
*/
|
||||
ACI_STATUS_ERROR_ADVT_TIMEOUT = 0x93,
|
||||
/**
|
||||
* Peer has triggered a Security Manager Protocol Error
|
||||
*/
|
||||
ACI_STATUS_ERROR_PEER_SMP_ERROR = 0x94,
|
||||
/**
|
||||
* Pipe Error Event : Pipe type invalid for the selected operation
|
||||
*/
|
||||
ACI_STATUS_ERROR_PIPE_TYPE_INVALID = 0x95,
|
||||
/**
|
||||
* Pipe Error Event : Pipe state invalid for the selected operation
|
||||
*/
|
||||
ACI_STATUS_ERROR_PIPE_STATE_INVALID = 0x96,
|
||||
/**
|
||||
* Invalid key size provided
|
||||
*/
|
||||
ACI_STATUS_ERROR_INVALID_KEY_SIZE = 0x97,
|
||||
/**
|
||||
* Invalid key data provided
|
||||
*/
|
||||
ACI_STATUS_ERROR_INVALID_KEY_DATA = 0x98,
|
||||
/**
|
||||
* Reserved range start
|
||||
*/
|
||||
ACI_STATUS_RESERVED_START = 0xF0,
|
||||
/**
|
||||
* Reserved range end
|
||||
*/
|
||||
ACI_STATUS_RESERVED_END = 0xFF
|
||||
|
||||
} aci_status_code_t;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif // ACI_H__
|
||||
404
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/aci_cmds.h
Executable file
404
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/aci_cmds.h
Executable file
@@ -0,0 +1,404 @@
|
||||
/* Copyright (c) 2010 Nordic Semiconductor. All Rights Reserved.
|
||||
*
|
||||
* The information contained herein is property of Nordic Semiconductor ASA.
|
||||
* Terms and conditions of usage are described in detail in NORDIC
|
||||
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
|
||||
*
|
||||
* Licensees are granted free, non-transferable use of the information. NO
|
||||
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
|
||||
* the file.
|
||||
*
|
||||
* $LastChangedRevision$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup aci
|
||||
*
|
||||
* @brief Definitions for the ACI (Application Control Interface) commands
|
||||
* @remarks
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ACI_CMDS_H__
|
||||
#define ACI_CMDS_H__
|
||||
|
||||
/**
|
||||
* @enum aci_cmd_opcode_t
|
||||
* @brief ACI command opcodes
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/**
|
||||
* Enter test mode
|
||||
*/
|
||||
ACI_CMD_TEST = 0x01,
|
||||
/**
|
||||
* Echo (loopback) test command
|
||||
*/
|
||||
ACI_CMD_ECHO = 0x02,
|
||||
/**
|
||||
* Send a BTLE DTM command to the radio
|
||||
*/
|
||||
ACI_CMD_DTM_CMD = 0x03,
|
||||
/**
|
||||
* Put the device to sleep
|
||||
*/
|
||||
ACI_CMD_SLEEP = 0x04,
|
||||
/**
|
||||
* Wakeup the device from deep sleep
|
||||
*/
|
||||
ACI_CMD_WAKEUP = 0x05,
|
||||
/**
|
||||
* Replace the contents of the internal database with
|
||||
* user provided data
|
||||
*/
|
||||
ACI_CMD_SETUP = 0x06,
|
||||
/**
|
||||
* Read the portions of memory required to be restored after a power cycle
|
||||
*/
|
||||
ACI_CMD_READ_DYNAMIC_DATA = 0x07,
|
||||
/**
|
||||
* Write back the data retrieved using ACI_CMD_READ_DYNAMIC_DATA
|
||||
*/
|
||||
ACI_CMD_WRITE_DYNAMIC_DATA = 0x08,
|
||||
/**
|
||||
* Retrieve the device's version information
|
||||
*/
|
||||
ACI_CMD_GET_DEVICE_VERSION = 0x09,
|
||||
/**
|
||||
* Request the Bluetooth address and its type
|
||||
*/
|
||||
ACI_CMD_GET_DEVICE_ADDRESS = 0x0A,
|
||||
/**
|
||||
* Request the battery level measured by nRF8001
|
||||
*/
|
||||
ACI_CMD_GET_BATTERY_LEVEL = 0x0B,
|
||||
/**
|
||||
* Request the temperature value measured by nRF8001
|
||||
*/
|
||||
ACI_CMD_GET_TEMPERATURE = 0x0C,
|
||||
/**
|
||||
* Write to the local Attribute Database
|
||||
*/
|
||||
ACI_CMD_SET_LOCAL_DATA = 0x0D,
|
||||
/**
|
||||
* Reset the baseband and radio and go back to idle
|
||||
*/
|
||||
ACI_CMD_RADIO_RESET = 0x0E,
|
||||
/**
|
||||
* Start advertising and wait for a master connection
|
||||
*/
|
||||
ACI_CMD_CONNECT = 0x0F,
|
||||
/**
|
||||
* Start advertising and wait for a master connection
|
||||
*/
|
||||
ACI_CMD_BOND = 0x10,
|
||||
/**
|
||||
* Start advertising and wait for a master connection
|
||||
*/
|
||||
ACI_CMD_DISCONNECT = 0x11,
|
||||
/**
|
||||
* Throttles the Radio transmit power
|
||||
*/
|
||||
ACI_CMD_SET_TX_POWER = 0x12,
|
||||
/**
|
||||
* Trigger a connection parameter update
|
||||
*/
|
||||
ACI_CMD_CHANGE_TIMING = 0x13,
|
||||
/**
|
||||
* Open a remote pipe for data reception
|
||||
*/
|
||||
ACI_CMD_OPEN_REMOTE_PIPE = 0x14,
|
||||
/**
|
||||
* Transmit data over an open pipe
|
||||
*/
|
||||
ACI_CMD_SEND_DATA = 0x15,
|
||||
/**
|
||||
* Send an acknowledgment of received data
|
||||
*/
|
||||
ACI_CMD_SEND_DATA_ACK = 0x16,
|
||||
/**
|
||||
* Request data over an open pipe
|
||||
*/
|
||||
ACI_CMD_REQUEST_DATA = 0x17,
|
||||
/**
|
||||
* NACK a data reception
|
||||
*/
|
||||
ACI_CMD_SEND_DATA_NACK = 0x18,
|
||||
/**
|
||||
* Set application latency
|
||||
*/
|
||||
ACI_CMD_SET_APP_LATENCY = 0x19,
|
||||
/**
|
||||
* Set a security key
|
||||
*/
|
||||
ACI_CMD_SET_KEY = 0x1A,
|
||||
/**
|
||||
* Open Advertising Pipes
|
||||
*/
|
||||
ACI_CMD_OPEN_ADV_PIPE = 0x1B,
|
||||
/**
|
||||
* Start non-connectable advertising
|
||||
*/
|
||||
ACI_CMD_BROADCAST = 0x1C,
|
||||
/**
|
||||
* Start a security request in bonding mode
|
||||
*/
|
||||
ACI_CMD_BOND_SECURITY_REQUEST = 0x1D,
|
||||
/**
|
||||
* Start Directed advertising towards a Bonded Peer
|
||||
*/
|
||||
ACI_CMD_CONNECT_DIRECT = 0x1E,
|
||||
/**
|
||||
* Close a previously opened remote pipe
|
||||
*/
|
||||
ACI_CMD_CLOSE_REMOTE_PIPE = 0x1F,
|
||||
/**
|
||||
* Invalid ACI command opcode
|
||||
*/
|
||||
ACI_CMD_INVALID = 0xFF
|
||||
|
||||
} aci_cmd_opcode_t;
|
||||
|
||||
/**
|
||||
* @struct aci_cmd_params_test_t
|
||||
* @brief Structure for the ACI_CMD_TEST ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t test_mode_change; /**< enum aci_test_mode_change_t */
|
||||
} aci_cmd_params_test_t;
|
||||
|
||||
/**
|
||||
* @struct aci_cmd_params_echo_t
|
||||
* @brief Structure for the ACI_CMD_ECHO ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t echo_data[ACI_ECHO_DATA_MAX_LEN];
|
||||
} aci_cmd_params_echo_t;
|
||||
|
||||
/**
|
||||
* @struct aci_cmd_params_dtm_cmd_t
|
||||
* @brief Structure for the ACI_CMD_DTM_CMD ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t cmd_msb;
|
||||
uint8_t cmd_lsb;
|
||||
} aci_cmd_params_dtm_cmd_t;
|
||||
|
||||
/**
|
||||
* @struct aci_cmd_params_setup_t
|
||||
* @brief Structure for the ACI_CMD_SETUP ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t setup_data[1];
|
||||
} aci_cmd_params_setup_t;
|
||||
|
||||
/**
|
||||
* @struct aci_cmd_params_write_dynamic_data_t
|
||||
* @brief Structure for the ACI_CMD_WRITE_DYNAMIC_DATA ACI command parameters
|
||||
* @note Dynamic data chunk size in this command is defined to go up to ACI_PACKET_MAX_LEN - 3
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t seq_no;
|
||||
uint8_t dynamic_data[1];
|
||||
} aci_cmd_params_write_dynamic_data_t;
|
||||
|
||||
/**
|
||||
* @define aci_cmd_params_set_local_data_t
|
||||
* @brief Structure for the ACI_CMD_SET_LOCAL_DATA ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
aci_tx_data_t tx_data;
|
||||
} aci_cmd_params_set_local_data_t;
|
||||
|
||||
/**
|
||||
* @struct aci_cmd_params_connect_t
|
||||
* @brief Structure for the ACI_CMD_CONNECT ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t timeout; /**< 0x0000 (no timeout) to 0x3FFF */
|
||||
uint16_t adv_interval; /**< 16 bits of advertising interval for general discovery */
|
||||
} aci_cmd_params_connect_t;
|
||||
|
||||
/**
|
||||
* @define aci_cmd_params_bond_t
|
||||
* @brief Structure for the ACI_CMD_BOND ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t timeout; /**< 0x0000 (no timeout) to 0x3FFF */
|
||||
uint16_t adv_interval; /**< 16 bits of advertising interval for general discovery */
|
||||
} aci_cmd_params_bond_t;
|
||||
|
||||
/**
|
||||
* @struct aci_cmd_params_disconnect_t
|
||||
* @brief Structure for the ACI_CMD_DISCONNECT ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t reason; /**< enum aci_disconnect_reason_t */
|
||||
} aci_cmd_params_disconnect_t;
|
||||
|
||||
/**
|
||||
* @struct aci_cmd_params_set_tx_power_t
|
||||
* @brief Structure for the ACI_CMD_SET_TX_POWER ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t device_power; /**< enum aci_device_output_power_t */
|
||||
} aci_cmd_params_set_tx_power_t;
|
||||
|
||||
/**
|
||||
* @struct aci_cmd_params_change_timing_t
|
||||
* @brief Structure for the ACI_CMD_CHANGE_TIMING ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
aci_ll_conn_params_t conn_params;
|
||||
} aci_cmd_params_change_timing_t;
|
||||
|
||||
/**
|
||||
* @struct aci_cmd_params_open_remote_pipe_t
|
||||
* @brief Structure for the ACI_CMD_OPEN_REMOTE_PIPE ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t pipe_number;
|
||||
} aci_cmd_params_open_remote_pipe_t;
|
||||
|
||||
/**
|
||||
* @struct aci_cmd_params_send_data_t
|
||||
* @brief Structure for the ACI_CMD_SEND_DATA ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
aci_tx_data_t tx_data;
|
||||
} aci_cmd_params_send_data_t;
|
||||
|
||||
/**
|
||||
* @define aci_cmd_params_send_data_ack_t
|
||||
* @brief Structure for the ACI_CMD_SEND_DATA_ACK ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t pipe_number;
|
||||
} aci_cmd_params_send_data_ack_t;
|
||||
|
||||
/**
|
||||
* @struct aci_cmd_params_send_data_t
|
||||
* @brief Structure for the ACI_CMD_SEND_DATA ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t pipe_number;
|
||||
} aci_cmd_params_request_data_t;
|
||||
|
||||
/**
|
||||
* @define aci_cmd_params_send_data_nack_t
|
||||
* @brief Structure for the ACI_CMD_SEND_DATA_NACK ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t pipe_number;
|
||||
uint8_t error_code;
|
||||
} aci_cmd_params_send_data_nack_t;
|
||||
|
||||
/**
|
||||
* @define aci_cmd_params_set_app_latency_t
|
||||
* @brief Structure for the ACI_CMD_SET_APP_LATENCY ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
aci_app_latency_mode_t mode;
|
||||
uint16_t latency;
|
||||
} aci_cmd_params_set_app_latency_t;
|
||||
|
||||
/**
|
||||
* @define aci_cmd_params_set_key_t
|
||||
* @brief Structure for the ACI_CMD_SET_KEY ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
aci_key_type_t key_type;
|
||||
union
|
||||
{
|
||||
uint8_t passkey[6];
|
||||
uint8_t oob_key[16];
|
||||
} key;
|
||||
} aci_cmd_params_set_key_t;
|
||||
|
||||
/**
|
||||
* @define aci_cmd_params_open_adv_pipe_t
|
||||
* @brief Structure for the ACI_CMD_OPEN_ADV_PIPE ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t pipes[8];
|
||||
} aci_cmd_params_open_adv_pipe_t;
|
||||
|
||||
/**
|
||||
* @define aci_cmd_params_broadcast_t
|
||||
* @brief Structure for the ACI_CMD_BROADCAST ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t timeout; /**< 0x0000 (no timeout) to 0x3FFF */
|
||||
uint16_t adv_interval; /**< 16 bits of advertising interval for general discovery */
|
||||
} aci_cmd_params_broadcast_t;
|
||||
|
||||
/**
|
||||
* @struct aci_cmd_params_close_remote_pipe_t
|
||||
* @brief Structure for the ACI_CMD_CLOSE_REMOTE_PIPE ACI command parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t pipe_number;
|
||||
} aci_cmd_params_close_remote_pipe_t;
|
||||
|
||||
/**
|
||||
* @struct aci_cmd_t
|
||||
* @brief Encapsulates a generic ACI command
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t len; /**< Length of the ACI command */
|
||||
uint8_t cmd_opcode; /**< enum aci_cmd_opcode_t -> Opcode of the ACI command */
|
||||
union
|
||||
{
|
||||
aci_cmd_params_test_t test;
|
||||
aci_cmd_params_echo_t echo;
|
||||
aci_cmd_params_dtm_cmd_t dtm_cmd;
|
||||
aci_cmd_params_setup_t setup;
|
||||
aci_cmd_params_write_dynamic_data_t write_dynamic_data;
|
||||
aci_cmd_params_set_local_data_t set_local_data;
|
||||
aci_cmd_params_connect_t connect;
|
||||
aci_cmd_params_bond_t bond;
|
||||
aci_cmd_params_disconnect_t disconnect;
|
||||
aci_cmd_params_set_tx_power_t set_tx_power;
|
||||
aci_cmd_params_change_timing_t change_timing;
|
||||
aci_cmd_params_open_remote_pipe_t open_remote_pipe;
|
||||
aci_cmd_params_send_data_t send_data;
|
||||
aci_cmd_params_send_data_ack_t send_data_ack;
|
||||
aci_cmd_params_request_data_t request_data;
|
||||
aci_cmd_params_send_data_nack_t send_data_nack;
|
||||
aci_cmd_params_set_app_latency_t set_app_latency;
|
||||
aci_cmd_params_set_key_t set_key;
|
||||
aci_cmd_params_open_adv_pipe_t open_adv_pipe;
|
||||
aci_cmd_params_broadcast_t broadcast;
|
||||
aci_cmd_params_close_remote_pipe_t close_remote_pipe;
|
||||
|
||||
} params;
|
||||
} aci_cmd_t;
|
||||
|
||||
#endif // ACI_CMDS_H__
|
||||
|
||||
|
||||
364
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/aci_evts.h
Executable file
364
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/aci_evts.h
Executable file
@@ -0,0 +1,364 @@
|
||||
/* Copyright (c) 2010 Nordic Semiconductor. All Rights Reserved.
|
||||
*
|
||||
* The information contained herein is property of Nordic Semiconductor ASA.
|
||||
* Terms and conditions of usage are described in detail in NORDIC
|
||||
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
|
||||
*
|
||||
* Licensees are granted free, non-transferable use of the information. NO
|
||||
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
|
||||
* the file.
|
||||
*
|
||||
* $LastChangedRevision$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup aci
|
||||
*
|
||||
* @brief Definitions for the ACI (Application Control Interface) events
|
||||
*/
|
||||
|
||||
#ifndef ACI_EVTS_H__
|
||||
#define ACI_EVTS_H__
|
||||
|
||||
#include "aci.h"
|
||||
/**
|
||||
* @enum aci_evt_opcode_t
|
||||
* @brief ACI event opcodes
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/**
|
||||
* Invalid event code
|
||||
*/
|
||||
ACI_EVT_INVALID = 0x00,
|
||||
/**
|
||||
* Sent every time the device starts
|
||||
*/
|
||||
ACI_EVT_DEVICE_STARTED = 0x81,
|
||||
/**
|
||||
* Mirrors the ACI_CMD_ECHO
|
||||
*/
|
||||
ACI_EVT_ECHO = 0x82,
|
||||
/**
|
||||
* Asynchronous hardware error event
|
||||
*/
|
||||
ACI_EVT_HW_ERROR = 0x83,
|
||||
/**
|
||||
* Event opcode used as a event response for all commands
|
||||
*/
|
||||
ACI_EVT_CMD_RSP = 0x84,
|
||||
/**
|
||||
* Link connected
|
||||
*/
|
||||
ACI_EVT_CONNECTED = 0x85,
|
||||
/**
|
||||
* Link disconnected
|
||||
*/
|
||||
ACI_EVT_DISCONNECTED = 0x86,
|
||||
/**
|
||||
* Bond completion result
|
||||
*/
|
||||
ACI_EVT_BOND_STATUS = 0x87,
|
||||
/**
|
||||
* Pipe bitmap for available pipes
|
||||
*/
|
||||
ACI_EVT_PIPE_STATUS = 0x88,
|
||||
/**
|
||||
* Sent to the application when the radio enters a connected state
|
||||
* or when the timing of the radio connection changes
|
||||
*/
|
||||
ACI_EVT_TIMING = 0x89,
|
||||
/**
|
||||
* Notification to the application that transmit credits are
|
||||
* available
|
||||
*/
|
||||
ACI_EVT_DATA_CREDIT = 0x8A,
|
||||
/**
|
||||
* Data acknowledgement event
|
||||
*/
|
||||
ACI_EVT_DATA_ACK = 0x8B,
|
||||
/**
|
||||
* Data received notification event
|
||||
*/
|
||||
ACI_EVT_DATA_RECEIVED = 0x8C,
|
||||
/**
|
||||
* Error notification event
|
||||
*/
|
||||
ACI_EVT_PIPE_ERROR = 0x8D,
|
||||
/**
|
||||
* Display Passkey Event
|
||||
*/
|
||||
ACI_EVT_DISPLAY_PASSKEY = 0x8E,
|
||||
/**
|
||||
* Security Key request
|
||||
*/
|
||||
ACI_EVT_KEY_REQUEST = 0x8F
|
||||
|
||||
} aci_evt_opcode_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_params_device_started_t
|
||||
* @brief Structure for the ACI_EVT_DEVICE_STARTED event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t device_mode; /**< enum aci_device_operation_mode_t -> Mode in which the device is being started */
|
||||
uint8_t hw_error; /**< enum aci_hw_error_t -> Hardware Error if available for the start */
|
||||
uint8_t credit_available; /**< Flow control credit available for this specific FW build */
|
||||
} aci_evt_params_device_started_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_params_hw_error_t
|
||||
* @brief Structure for the ACI_EVT_HW_ERROR event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t line_num;
|
||||
uint8_t file_name[20];
|
||||
} aci_evt_params_hw_error_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_cmd_rsp_params_dtm_cmd_t
|
||||
* @brief Structure for the ACI_EVT_CMD_RSP event with opcode=ACI_CMD_DTM_CMD event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t evt_msb;
|
||||
uint8_t evt_lsb;
|
||||
} aci_evt_cmd_rsp_params_dtm_cmd_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_cmd_rsp_read_dynamic_data_t
|
||||
* @brief Structure for the ACI_EVT_CMD_RSP event with opcode=ACI_CMD_READ_DYNAMIC_DATA event return parameters
|
||||
* @note Dynamic data chunk size in this event is defined to go up to ACI_PACKET_MAX_LEN - 5
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t seq_no;
|
||||
uint8_t dynamic_data[1];
|
||||
} aci_evt_cmd_rsp_read_dynamic_data_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_cmd_rsp_params_get_device_version_t
|
||||
* @brief Structure for the ACI_EVT_CMD_RSP event with opcode=ACI_CMD_GET_DEVICE_VERSION event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t configuration_id;
|
||||
uint8_t aci_version;
|
||||
uint8_t setup_format;
|
||||
uint32_t setup_id;
|
||||
uint8_t setup_status;
|
||||
} aci_evt_cmd_rsp_params_get_device_version_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_cmd_rsp_params_get_device_address_t
|
||||
* @brief Structure for the ACI_EVT_CMD_RSP event with opcode=ACI_CMD_GET_DEVICE_ADDRESS event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bd_addr_own[BTLE_DEVICE_ADDRESS_SIZE];
|
||||
uint8_t bd_addr_type; /**< enum aci_bd_addr_type_t */
|
||||
} aci_evt_cmd_rsp_params_get_device_address_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_cmd_rsp_params_get_battery_level_t
|
||||
* @brief Structure for the ACI_EVT_CMD_RSP event with opcode=ACI_CMD_GET_BATTERY_LEVEL event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t battery_level;
|
||||
} aci_evt_cmd_rsp_params_get_battery_level_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_cmd_rsp_params_get_temperature_t
|
||||
* @brief Structure for the ACI_EVT_CMD_RSP event with opcode=ACI_CMD_GET_TEMPERATURE event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int16_t temperature_value;
|
||||
} aci_evt_cmd_rsp_params_get_temperature_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_params_cmd_rsp_t
|
||||
* @brief Structure for the ACI_EVT_CMD_RSP event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t cmd_opcode; /**< enum aci_cmd_opcode_t -> Command opcode for which the event response is being sent */
|
||||
uint8_t cmd_status; /**< enum aci_status_code_t -> Status of the command that was sent. Used in the context of the command. */
|
||||
union
|
||||
{
|
||||
aci_evt_cmd_rsp_params_dtm_cmd_t dtm_cmd;
|
||||
aci_evt_cmd_rsp_read_dynamic_data_t read_dynamic_data;
|
||||
aci_evt_cmd_rsp_params_get_device_version_t get_device_version;
|
||||
aci_evt_cmd_rsp_params_get_device_address_t get_device_address;
|
||||
aci_evt_cmd_rsp_params_get_battery_level_t get_battery_level;
|
||||
aci_evt_cmd_rsp_params_get_temperature_t get_temperature;
|
||||
uint8_t padding[29];
|
||||
} params;
|
||||
} aci_evt_params_cmd_rsp_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_params_connected_t
|
||||
* @brief Structure for the ACI_EVT_CONNECTED event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
aci_bd_addr_type_t dev_addr_type;
|
||||
uint8_t dev_addr[BTLE_DEVICE_ADDRESS_SIZE];
|
||||
uint16_t conn_rf_interval; /**< rf_interval = conn_rf_interval * 1.25 ms Range:0x0006 to 0x0C80 */
|
||||
uint16_t conn_slave_rf_latency; /**< Number of RF events the slave can skip */
|
||||
uint16_t conn_rf_timeout; /**< Timeout as a multiple of 10ms i.e timeout = conn_rf_timeout * 10ms Range: 0x000A to 0x0C80 */
|
||||
uint8_t master_clock_accuracy; /**< enum aci_clock_accuracy_t -> Clock accuracy of Bluetooth master: Enumerated list of values from 500 ppm to 20 ppm */
|
||||
} aci_evt_params_connected_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_params_disconnected_t
|
||||
* @brief Structure for the ACI_EVT_DISCONNECTED event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t aci_status; /**< enum aci_status_code_t */
|
||||
uint8_t btle_status;
|
||||
} aci_evt_params_disconnected_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_params_bond_status_t
|
||||
* @brief Structure for the ACI_EVT_BOND_STATUS event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t status_code;
|
||||
uint8_t status_source; /**< enum aci_bond_status_source_t */
|
||||
uint8_t secmode1_bitmap;
|
||||
uint8_t secmode2_bitmap;
|
||||
uint8_t keys_exchanged_slave;
|
||||
uint8_t keys_exchanged_master;
|
||||
} aci_evt_params_bond_status_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_params_pipe_status_t
|
||||
* @brief Structure for the ACI_EVT_PIPE_STATUS event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t pipes_open_bitmap[8];
|
||||
uint8_t pipes_closed_bitmap[8];
|
||||
} aci_evt_params_pipe_status_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_params_timing_t
|
||||
* @brief Structure for the ACI_EVT_TIMING event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t conn_rf_interval; /**< rf_interval = conn_rf_interval * 1.25 ms Range:0x0006 to 0x0C80 */
|
||||
uint16_t conn_slave_rf_latency; /**< Number of RF events the slave can skip */
|
||||
uint16_t conn_rf_timeout; /**< Timeout as a multiple of 10ms i.e timeout = conn_rf_timeout * 10ms Range: 0x000A to 0x0C80 */
|
||||
} aci_evt_params_timing_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_params_data_credit_t
|
||||
* @brief Structure for the ACI_EVT_DATA_CREDIT event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t credit;
|
||||
} aci_evt_params_data_credit_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_params_data_ack_t
|
||||
* @brief Structure for the ACI_EVT_DATA_ACK event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t pipe_number;
|
||||
} aci_evt_params_data_ack_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_params_data_received_t
|
||||
* @brief Structure for the ACI_EVT_DATA_RECEIVED event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
aci_rx_data_t rx_data;
|
||||
} aci_evt_params_data_received_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t content[1];
|
||||
} error_data_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_params_pipe_error_t
|
||||
* @brief Structure for the ACI_EVT_PIPE_ERROR event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t pipe_number;
|
||||
uint8_t error_code;
|
||||
union
|
||||
{
|
||||
error_data_t error_data;
|
||||
} params;
|
||||
} aci_evt_params_pipe_error_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_params_display_passkey_t
|
||||
* @brief Structure for the ACI_EVT_DISPLAY_PASSKEY event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t passkey[6];
|
||||
} aci_evt_params_display_passkey_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_params_key_request_t
|
||||
* @brief Structure for the ACI_EVT_KEY_REQUEST event return parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t key_type; /**< enum aci_key_type_t */
|
||||
} aci_evt_params_key_request_t;
|
||||
|
||||
/**
|
||||
* @struct aci_event_params_echo_t
|
||||
* @brief Structure for the ACI_EVT_ECHO ACI event parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t echo_data[ACI_ECHO_DATA_MAX_LEN];
|
||||
} aci_evt_params_echo_t;
|
||||
|
||||
/**
|
||||
* @struct aci_evt_t
|
||||
* @brief Encapsulates a generic ACI event
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t len;
|
||||
uint8_t evt_opcode; /** enum aci_evt_opcode_t */
|
||||
union
|
||||
{
|
||||
aci_evt_params_device_started_t device_started;
|
||||
aci_evt_params_echo_t echo;
|
||||
aci_evt_params_hw_error_t hw_error;
|
||||
aci_evt_params_cmd_rsp_t cmd_rsp;
|
||||
aci_evt_params_connected_t connected;
|
||||
aci_evt_params_disconnected_t disconnected;
|
||||
aci_evt_params_bond_status_t bond_status;
|
||||
aci_evt_params_pipe_status_t pipe_status;
|
||||
aci_evt_params_timing_t timing;
|
||||
aci_evt_params_data_credit_t data_credit;
|
||||
aci_evt_params_data_ack_t data_ack;
|
||||
aci_evt_params_data_received_t data_received;
|
||||
aci_evt_params_pipe_error_t pipe_error;
|
||||
aci_evt_params_display_passkey_t display_passkey;
|
||||
aci_evt_params_key_request_t key_request;
|
||||
} params;
|
||||
} aci_evt_t;
|
||||
|
||||
#endif // ACI_EVTS_H__
|
||||
@@ -0,0 +1,178 @@
|
||||
/* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved. *
|
||||
* *
|
||||
* The information contained herein is property of Nordic Semiconductor ASA.*
|
||||
* Terms and conditions of usage are described in detail in NORDIC *
|
||||
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. *
|
||||
* *
|
||||
* Licensees are granted free, non-transferable use of the information. NO *
|
||||
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from *
|
||||
* the file. *
|
||||
* */
|
||||
|
||||
/* *
|
||||
* This file contents defines for the position of all the fields of ACI *
|
||||
* command or event messages *
|
||||
* */
|
||||
|
||||
#ifndef ACI_OFFSET_H__
|
||||
#define ACI_OFFSET_H__
|
||||
|
||||
|
||||
#define OFFSET_ACI_LL_CONN_PARAMS_T_MIN_CONN_INTERVAL_LSB 0
|
||||
#define OFFSET_ACI_LL_CONN_PARAMS_T_MIN_CONN_INTERVAL_MSB 1
|
||||
#define OFFSET_ACI_LL_CONN_PARAMS_T_MAX_CONN_INTERVAL_LSB 2
|
||||
#define OFFSET_ACI_LL_CONN_PARAMS_T_MAX_CONN_INTERVAL_MSB 3
|
||||
#define OFFSET_ACI_LL_CONN_PARAMS_T_SLAVE_LATENCY_LSB 4
|
||||
#define OFFSET_ACI_LL_CONN_PARAMS_T_SLAVE_LATENCY_MSB 5
|
||||
#define OFFSET_ACI_LL_CONN_PARAMS_T_TIMEOUT_MULT_LSB 6
|
||||
#define OFFSET_ACI_LL_CONN_PARAMS_T_TIMEOUT_MULT_MSB 7
|
||||
#define OFFSET_ACI_TX_DATA_T_PIPE_NUMBER 0
|
||||
#define OFFSET_ACI_TX_DATA_T_ACI_DATA 1
|
||||
#define OFFSET_ACI_RX_DATA_T_PIPE_NUMBER 0
|
||||
#define OFFSET_ACI_RX_DATA_T_ACI_DATA 1
|
||||
#define OFFSET_ACI_CMD_PARAMS_TEST_T_TEST_MODE_CHANGE 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_ECHO_T_ECHO_DATA 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_DTM_CMD_T_CMD_MSB 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_DTM_CMD_T_CMD_LSB 1
|
||||
#define OFFSET_ACI_CMD_PARAMS_SETUP_T_SETUP_DATA 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_WRITE_DYNAMIC_DATA_T_SEQ_NO 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_WRITE_DYNAMIC_DATA_T_DYNAMIC_DATA 1
|
||||
#define OFFSET_ACI_CMD_PARAMS_SET_LOCAL_DATA_T_TX_DATA 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_CONNECT_T_TIMEOUT_LSB 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_CONNECT_T_TIMEOUT_MSB 1
|
||||
#define OFFSET_ACI_CMD_PARAMS_CONNECT_T_ADV_INTERVAL_LSB 2
|
||||
#define OFFSET_ACI_CMD_PARAMS_CONNECT_T_ADV_INTERVAL_MSB 3
|
||||
#define OFFSET_ACI_CMD_PARAMS_BOND_T_TIMEOUT_LSB 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_BOND_T_TIMEOUT_MSB 1
|
||||
#define OFFSET_ACI_CMD_PARAMS_BOND_T_ADV_INTERVAL_LSB 2
|
||||
#define OFFSET_ACI_CMD_PARAMS_BOND_T_ADV_INTERVAL_MSB 3
|
||||
#define OFFSET_ACI_CMD_PARAMS_DISCONNECT_T_REASON 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_SET_TX_POWER_T_DEVICE_POWER 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_CHANGE_TIMING_T_CONN_PARAMS 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_OPEN_REMOTE_PIPE_T_PIPE_NUMBER 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_SEND_DATA_T_TX_DATA 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_SEND_DATA_ACK_T_PIPE_NUMBER 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_REQUEST_DATA_T_PIPE_NUMBER 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_SEND_DATA_NACK_T_PIPE_NUMBER 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_SEND_DATA_NACK_T_ERROR_CODE 1
|
||||
#define OFFSET_ACI_CMD_PARAMS_SET_APP_LATENCY_T_MODE 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_SET_APP_LATENCY_T_LATENCY_LSB 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_SET_APP_LATENCY_T_LATENCY_MSB 1
|
||||
#define OFFSET_ACI_CMD_PARAMS_SET_KEY_T_KEY_TYPE 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_SET_KEY_T_PASSKEY 1
|
||||
#define OFFSET_ACI_CMD_PARAMS_SET_KEY_T_OOB_KEY 1
|
||||
#define OFFSET_ACI_CMD_PARAMS_OPEN_ADV_PIPE_T_PIPES 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_BROADCAST_T_TIMEOUT_LSB 0
|
||||
#define OFFSET_ACI_CMD_PARAMS_BROADCAST_T_TIMEOUT_MSB 1
|
||||
#define OFFSET_ACI_CMD_PARAMS_BROADCAST_T_ADV_INTERVAL_LSB 2
|
||||
#define OFFSET_ACI_CMD_PARAMS_BROADCAST_T_ADV_INTERVAL_MSB 3
|
||||
#define OFFSET_ACI_CMD_PARAMS_CLOSE_REMOTE_PIPE_T_PIPE_NUMBER 0
|
||||
#define OFFSET_ACI_CMD_T_LEN 0
|
||||
#define OFFSET_ACI_CMD_T_CMD_OPCODE 1
|
||||
#define OFFSET_ACI_CMD_T_TEST 2
|
||||
#define OFFSET_ACI_CMD_T_ECHO 2
|
||||
#define OFFSET_ACI_CMD_T_DTM_CMD 2
|
||||
#define OFFSET_ACI_CMD_T_SETUP 2
|
||||
#define OFFSET_ACI_CMD_T_WRITE_DYNAMIC_DATA 2
|
||||
#define OFFSET_ACI_CMD_T_SET_LOCAL_DATA 2
|
||||
#define OFFSET_ACI_CMD_T_CONNECT 2
|
||||
#define OFFSET_ACI_CMD_T_BOND 2
|
||||
#define OFFSET_ACI_CMD_T_DISCONNECT 2
|
||||
#define OFFSET_ACI_CMD_T_SET_TX_POWER 2
|
||||
#define OFFSET_ACI_CMD_T_CHANGE_TIMING 2
|
||||
#define OFFSET_ACI_CMD_T_OPEN_REMOTE_PIPE 2
|
||||
#define OFFSET_ACI_CMD_T_SEND_DATA 2
|
||||
#define OFFSET_ACI_CMD_T_SEND_DATA_ACK 2
|
||||
#define OFFSET_ACI_CMD_T_REQUEST_DATA 2
|
||||
#define OFFSET_ACI_CMD_T_SEND_DATA_NACK 2
|
||||
#define OFFSET_ACI_CMD_T_SET_APP_LATENCY 2
|
||||
#define OFFSET_ACI_CMD_T_SET_KEY 2
|
||||
#define OFFSET_ACI_CMD_T_OPEN_ADV_PIPE 2
|
||||
#define OFFSET_ACI_CMD_T_BROADCAST 2
|
||||
#define OFFSET_ACI_CMD_T_CLOSE_REMOTE_PIPE 2
|
||||
#define OFFSET_ACI_EVT_PARAMS_DEVICE_STARTED_T_DEVICE_MODE 0
|
||||
#define OFFSET_ACI_EVT_PARAMS_DEVICE_STARTED_T_HW_ERROR 1
|
||||
#define OFFSET_ACI_EVT_PARAMS_DEVICE_STARTED_T_CREDIT_AVAILABLE 2
|
||||
#define OFFSET_ACI_EVT_PARAMS_HW_ERROR_T_LINE_NUM_LSB 0
|
||||
#define OFFSET_ACI_EVT_PARAMS_HW_ERROR_T_LINE_NUM_MSB 1
|
||||
#define OFFSET_ACI_EVT_PARAMS_HW_ERROR_T_FILE_NAME 2
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_DTM_CMD_T_EVT_MSB 0
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_DTM_CMD_T_EVT_LSB 1
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_READ_DYNAMIC_DATA_T_SEQ_NO 0
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_READ_DYNAMIC_DATA_T_DYNAMIC_DATA 1
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_CONFIGURATION_ID_LSB 0
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_CONFIGURATION_ID_MSB 1
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_ACI_VERSION 2
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_FORMAT 3
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_ID_LSB0 4
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_ID_LSB1 5
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_ID_MSB0 6
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_ID_MSB1 7
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_STATUS 8
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_ADDRESS_T_BD_ADDR_OWN 0
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_ADDRESS_T_BD_ADDR_TYPE 6
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_BATTERY_LEVEL_T_BATTERY_LEVEL_LSB 0
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_BATTERY_LEVEL_T_BATTERY_LEVEL_MSB 1
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_TEMPERATURE_T_TEMPERATURE_VALUE_LSB 0
|
||||
#define OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_TEMPERATURE_T_TEMPERATURE_VALUE_MSB 1
|
||||
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_CMD_OPCODE 0
|
||||
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_CMD_STATUS 1
|
||||
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_DTM_CMD 2
|
||||
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_READ_DYNAMIC_DATA 2
|
||||
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_DEVICE_VERSION 2
|
||||
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_DEVICE_ADDRESS 2
|
||||
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_BATTERY_LEVEL 2
|
||||
#define OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_TEMPERATURE 2
|
||||
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_DEV_ADDR_TYPE 0
|
||||
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_DEV_ADDR 1
|
||||
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_RF_INTERVAL_LSB 7
|
||||
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_RF_INTERVAL_MSB 8
|
||||
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_SLAVE_RF_LATENCY_LSB 9
|
||||
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_SLAVE_RF_LATENCY_MSB 10
|
||||
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_RF_TIMEOUT_LSB 11
|
||||
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_RF_TIMEOUT_MSB 12
|
||||
#define OFFSET_ACI_EVT_PARAMS_CONNECTED_T_MASTER_CLOCK_ACCURACY 13
|
||||
#define OFFSET_ACI_EVT_PARAMS_DISCONNECTED_T_ACI_STATUS 0
|
||||
#define OFFSET_ACI_EVT_PARAMS_DISCONNECTED_T_BTLE_STATUS 1
|
||||
#define OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_STATUS_CODE 0
|
||||
#define OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_STATUS_SOURCE 1
|
||||
#define OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_SECMODE1_BITMAP 2
|
||||
#define OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_SECMODE2_BITMAP 3
|
||||
#define OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_KEYS_EXCHANGED_SLAVE 4
|
||||
#define OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_KEYS_EXCHANGED_MASTER 5
|
||||
#define OFFSET_ACI_EVT_PARAMS_PIPE_STATUS_T_PIPES_OPEN_BITMAP 0
|
||||
#define OFFSET_ACI_EVT_PARAMS_PIPE_STATUS_T_PIPES_CLOSED_BITMAP 8
|
||||
#define OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_RF_INTERVAL_LSB 0
|
||||
#define OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_RF_INTERVAL_MSB 1
|
||||
#define OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_SLAVE_RF_LATENCY_LSB 2
|
||||
#define OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_SLAVE_RF_LATENCY_MSB 3
|
||||
#define OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_RF_TIMEOUT_LSB 4
|
||||
#define OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_RF_TIMEOUT_MSB 5
|
||||
#define OFFSET_ACI_EVT_PARAMS_DATA_CREDIT_T_CREDIT 0
|
||||
#define OFFSET_ACI_EVT_PARAMS_DATA_ACK_T_PIPE_NUMBER 0
|
||||
#define OFFSET_ACI_EVT_PARAMS_DATA_RECEIVED_T_RX_DATA 0
|
||||
#define OFFSET_ERROR_DATA_T_CONTENT 0
|
||||
#define OFFSET_ACI_EVT_PARAMS_PIPE_ERROR_T_PIPE_NUMBER 0
|
||||
#define OFFSET_ACI_EVT_PARAMS_PIPE_ERROR_T_ERROR_CODE 1
|
||||
#define OFFSET_ACI_EVT_PARAMS_PIPE_ERROR_T_ERROR_DATA 2
|
||||
#define OFFSET_ACI_EVT_PARAMS_DISPLAY_PASSKEY_T_PASSKEY 0
|
||||
#define OFFSET_ACI_EVT_PARAMS_KEY_REQUEST_T_KEY_TYPE 0
|
||||
#define OFFSET_ACI_EVT_T_LEN 0
|
||||
#define OFFSET_ACI_EVT_T_EVT_OPCODE 1
|
||||
#define OFFSET_ACI_EVT_T_DEVICE_STARTED 2
|
||||
#define OFFSET_ACI_EVT_T_HW_ERROR 2
|
||||
#define OFFSET_ACI_EVT_T_CMD_RSP 2
|
||||
#define OFFSET_ACI_EVT_T_CONNECTED 2
|
||||
#define OFFSET_ACI_EVT_T_DISCONNECTED 2
|
||||
#define OFFSET_ACI_EVT_T_BOND_STATUS 2
|
||||
#define OFFSET_ACI_EVT_T_PIPE_STATUS 2
|
||||
#define OFFSET_ACI_EVT_T_TIMING 2
|
||||
#define OFFSET_ACI_EVT_T_DATA_CREDIT 2
|
||||
#define OFFSET_ACI_EVT_T_DATA_ACK 2
|
||||
#define OFFSET_ACI_EVT_T_DATA_RECEIVED 2
|
||||
#define OFFSET_ACI_EVT_T_PIPE_ERROR 2
|
||||
#define OFFSET_ACI_EVT_T_DISPLAY_PASSKEY 2
|
||||
#define OFFSET_ACI_EVT_T_KEY_REQUEST 2
|
||||
|
||||
#endif //ACI_OFFSET_H__
|
||||
|
||||
131
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/aci_setup.cpp
Executable file
131
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/aci_setup.cpp
Executable file
@@ -0,0 +1,131 @@
|
||||
/* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
|
||||
*
|
||||
* The information contained herein is property of Nordic Semiconductor ASA.
|
||||
* Terms and conditions of usage are described in detail in NORDIC
|
||||
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
|
||||
*
|
||||
* Licensees are granted free, non-transferable use of the information. NO
|
||||
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
|
||||
* the file.
|
||||
*
|
||||
* $LastChangedRevision$
|
||||
*/
|
||||
|
||||
/**
|
||||
* My project template
|
||||
*/
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
#include <ble_system.h>
|
||||
#include <lib_aci.h>
|
||||
#include "aci_setup.h"
|
||||
|
||||
|
||||
// aci_struct that will contain
|
||||
// total initial credits
|
||||
// current credit
|
||||
// current state of the aci (setup/standby/active/sleep)
|
||||
// open remote pipe pending
|
||||
// close remote pipe pending
|
||||
// Current pipe available bitmap
|
||||
// Current pipe closed bitmap
|
||||
// Current connection interval, slave latency and link supervision timeout
|
||||
// Current State of the the GATT client (Service Discovery status)
|
||||
|
||||
static hal_aci_evt_t aci_data;
|
||||
static hal_aci_data_t aci_cmd;
|
||||
|
||||
aci_status_code_t aci_setup(aci_state_t *aci_stat, uint8_t num_cmds, uint8_t num_cmd_offset)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint8_t evt_count = 0;
|
||||
aci_evt_t * aci_evt = NULL;
|
||||
|
||||
while (i < num_cmds)
|
||||
{
|
||||
//Copy the setup ACI message from Flash to RAM
|
||||
//Add 2 bytes to the length byte for status byte, length for the total number of bytes
|
||||
memcpy_P(&aci_cmd, &(aci_stat->aci_setup_info.setup_msgs[num_cmd_offset+i]),
|
||||
pgm_read_byte_near(&(aci_stat->aci_setup_info.setup_msgs[num_cmd_offset+i].buffer[0]))+2);
|
||||
|
||||
//Put the Setup ACI message in the command queue
|
||||
if (!hal_aci_tl_send(&aci_cmd))
|
||||
{
|
||||
Serial.println(F("Cmd Queue Full"));
|
||||
return ACI_STATUS_ERROR_INTERNAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Debug messages:
|
||||
//Serial.print(F("Setup msg"));
|
||||
//Serial.println(i, DEC);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
//We will sit here if we do not get the same number of command response evts as the commands sent to the ACI
|
||||
//
|
||||
//@check The setup wil fail in the while(1) below when the 32KHz source for the nRF8001 is in-correct in the setup generated in the nRFgo studio
|
||||
if (true == lib_aci_event_get(aci_stat, &aci_data))
|
||||
{
|
||||
aci_evt = &aci_data.evt;
|
||||
|
||||
evt_count++;
|
||||
|
||||
if (ACI_EVT_CMD_RSP != aci_evt->evt_opcode )
|
||||
{
|
||||
//Got something other than a command response evt -> Error
|
||||
return ACI_STATUS_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
if (!((ACI_STATUS_TRANSACTION_CONTINUE == aci_evt->params.cmd_rsp.cmd_status) ||
|
||||
(ACI_STATUS_TRANSACTION_COMPLETE == aci_evt->params.cmd_rsp.cmd_status)))
|
||||
{
|
||||
return (aci_status_code_t )aci_evt->params.cmd_rsp.cmd_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Serial.print(F("Cmd Response Evt "));
|
||||
//Serial.println(evt_count);
|
||||
}
|
||||
|
||||
if (num_cmds == evt_count)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ((aci_status_code_t)aci_evt->params.cmd_rsp.cmd_status);
|
||||
}
|
||||
|
||||
|
||||
aci_status_code_t do_aci_setup(aci_state_t *aci_stat)
|
||||
{
|
||||
aci_status_code_t status = ACI_STATUS_ERROR_CRC_MISMATCH;
|
||||
uint8_t i=0;
|
||||
|
||||
if(ACI_QUEUE_SIZE >= aci_stat->aci_setup_info.num_setup_msgs)
|
||||
{
|
||||
status = aci_setup(aci_stat, aci_stat->aci_setup_info.num_setup_msgs, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i=0; i<(aci_stat->aci_setup_info.num_setup_msgs/ACI_QUEUE_SIZE); i++)
|
||||
{
|
||||
//Serial.print(ACI_QUEUE_SIZE, DEC);
|
||||
//Serial.print(F(" "));
|
||||
//Serial.println(0+(ACI_QUEUE_SIZE*i), DEC);
|
||||
status = aci_setup(aci_stat, ACI_QUEUE_SIZE, (ACI_QUEUE_SIZE*i));
|
||||
}
|
||||
if ((aci_stat->aci_setup_info.num_setup_msgs % ACI_QUEUE_SIZE) != 0)
|
||||
{
|
||||
status = aci_setup(aci_stat, aci_stat->aci_setup_info.num_setup_msgs % ACI_QUEUE_SIZE, (ACI_QUEUE_SIZE*i));
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
12
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/aci_setup.h
Executable file
12
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/aci_setup.h
Executable file
@@ -0,0 +1,12 @@
|
||||
#ifndef H_ACI_SETUP
|
||||
#define H_ACI_SETUP
|
||||
|
||||
#define ACI_CMD_Q_SIZE 16
|
||||
|
||||
/**
|
||||
Do the ACI setup by sending the setup messages generated by the nRFgo studio to the nRF8001.
|
||||
After all the setup messages are sent. The nRF8001 will send a Device Started Event (Mode = STANDBY)
|
||||
*/
|
||||
aci_status_code_t do_aci_setup(aci_state_t *aci_stat);
|
||||
|
||||
#endif
|
||||
602
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/acilib.cpp
Executable file
602
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/acilib.cpp
Executable file
@@ -0,0 +1,602 @@
|
||||
/* Copyright (c) 2010 Nordic Semiconductor. All Rights Reserved.
|
||||
*
|
||||
* The information contained herein is property of Nordic Semiconductor ASA.
|
||||
* Terms and conditions of usage are described in detail in NORDIC
|
||||
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
|
||||
*
|
||||
* Licensees are granted free, non-transferable use of the information. NO
|
||||
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
|
||||
* the file.
|
||||
*
|
||||
* $LastChangedRevision$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup group_acilib
|
||||
*
|
||||
* @brief Implementation of the acilib module.
|
||||
*/
|
||||
|
||||
|
||||
#include "hal_platform.h"
|
||||
#include "aci.h"
|
||||
#include "aci_cmds.h"
|
||||
#include "aci_evts.h"
|
||||
#include "acilib.h"
|
||||
#include "aci_protocol_defines.h"
|
||||
#include "acilib_defs.h"
|
||||
#include "acilib_if.h"
|
||||
#include "acilib_types.h"
|
||||
|
||||
|
||||
void acil_encode_cmd_set_test_mode(uint8_t *buffer, aci_cmd_params_test_t *p_aci_cmd_params_test)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = 2;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_TEST;
|
||||
*(buffer + OFFSET_ACI_CMD_T_TEST + OFFSET_ACI_CMD_PARAMS_TEST_T_TEST_MODE_CHANGE) = p_aci_cmd_params_test->test_mode_change;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_sleep(uint8_t *buffer)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = 1;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_SLEEP;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_get_device_version(uint8_t *buffer)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = 1;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_GET_DEVICE_VERSION;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_set_local_data(uint8_t *buffer, aci_cmd_params_set_local_data_t *p_aci_cmd_params_set_local_data, uint8_t data_size)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_SET_LOCAL_DATA_BASE_LEN + data_size;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_SET_LOCAL_DATA;
|
||||
*(buffer + OFFSET_ACI_CMD_T_SET_LOCAL_DATA + OFFSET_ACI_CMD_PARAMS_SEND_DATA_T_TX_DATA + OFFSET_ACI_TX_DATA_T_PIPE_NUMBER) = p_aci_cmd_params_set_local_data->tx_data.pipe_number;
|
||||
memcpy(buffer + OFFSET_ACI_CMD_T_SET_LOCAL_DATA + OFFSET_ACI_CMD_PARAMS_SEND_DATA_T_TX_DATA + OFFSET_ACI_TX_DATA_T_ACI_DATA, &(p_aci_cmd_params_set_local_data->tx_data.aci_data[0]), data_size);
|
||||
}
|
||||
|
||||
void acil_encode_cmd_connect(uint8_t *buffer, aci_cmd_params_connect_t *p_aci_cmd_params_connect)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_CONNECT_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_CONNECT;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CONNECT + OFFSET_ACI_CMD_PARAMS_CONNECT_T_TIMEOUT_MSB) = (uint8_t)(p_aci_cmd_params_connect->timeout >> 8);
|
||||
*(buffer + OFFSET_ACI_CMD_T_CONNECT + OFFSET_ACI_CMD_PARAMS_CONNECT_T_TIMEOUT_LSB) = (uint8_t)(p_aci_cmd_params_connect->timeout);
|
||||
*(buffer + OFFSET_ACI_CMD_T_CONNECT + OFFSET_ACI_CMD_PARAMS_CONNECT_T_ADV_INTERVAL_MSB) = (uint8_t)(p_aci_cmd_params_connect->adv_interval >> 8);
|
||||
*(buffer + OFFSET_ACI_CMD_T_CONNECT + OFFSET_ACI_CMD_PARAMS_CONNECT_T_ADV_INTERVAL_LSB) = (uint8_t)(p_aci_cmd_params_connect->adv_interval);
|
||||
}
|
||||
|
||||
void acil_encode_cmd_bond(uint8_t *buffer, aci_cmd_params_bond_t *p_aci_cmd_params_bond)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_BOND_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_BOND;
|
||||
*(buffer + OFFSET_ACI_CMD_T_BOND + OFFSET_ACI_CMD_PARAMS_BOND_T_TIMEOUT_MSB) = (uint8_t)(p_aci_cmd_params_bond->timeout >> 8);
|
||||
*(buffer + OFFSET_ACI_CMD_T_BOND + OFFSET_ACI_CMD_PARAMS_BOND_T_TIMEOUT_LSB) = (uint8_t)(p_aci_cmd_params_bond->timeout);
|
||||
*(buffer + OFFSET_ACI_CMD_T_BOND + OFFSET_ACI_CMD_PARAMS_BOND_T_ADV_INTERVAL_MSB) = (uint8_t)(p_aci_cmd_params_bond->adv_interval >> 8);
|
||||
*(buffer + OFFSET_ACI_CMD_T_BOND + OFFSET_ACI_CMD_PARAMS_BOND_T_ADV_INTERVAL_LSB) = (uint8_t)(p_aci_cmd_params_bond->adv_interval);
|
||||
}
|
||||
|
||||
void acil_encode_cmd_disconnect(uint8_t *buffer, aci_cmd_params_disconnect_t *p_aci_cmd_params_disconnect)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_DISCONNECT_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_DISCONNECT;
|
||||
*(buffer + OFFSET_ACI_CMD_T_DISCONNECT + OFFSET_ACI_CMD_PARAMS_DISCONNECT_T_REASON) = (uint8_t)(p_aci_cmd_params_disconnect->reason);
|
||||
}
|
||||
|
||||
void acil_encode_baseband_reset(uint8_t *buffer)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_BASEBAND_RESET_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_RADIO_RESET;
|
||||
}
|
||||
|
||||
void acil_encode_direct_connect(uint8_t *buffer)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_DIRECT_CONNECT_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_CONNECT_DIRECT;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_wakeup(uint8_t *buffer)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_WAKEUP_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_WAKEUP;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_set_radio_tx_power(uint8_t *buffer, aci_cmd_params_set_tx_power_t *p_aci_cmd_params_set_tx_power)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_SET_RADIO_TX_POWER_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_SET_TX_POWER;
|
||||
*(buffer + OFFSET_ACI_CMD_T_SET_TX_POWER + OFFSET_ACI_CMD_PARAMS_SET_TX_POWER_T_DEVICE_POWER) = (uint8_t)p_aci_cmd_params_set_tx_power->device_power;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_get_address(uint8_t *buffer)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_GET_DEVICE_ADDR_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_GET_DEVICE_ADDRESS;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_send_data(uint8_t *buffer, aci_cmd_params_send_data_t *p_aci_cmd_params_send_data_t, uint8_t data_size)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_SEND_DATA_BASE_LEN + data_size;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_SEND_DATA;
|
||||
*(buffer + OFFSET_ACI_CMD_T_SEND_DATA + OFFSET_ACI_CMD_PARAMS_SEND_DATA_T_TX_DATA + OFFSET_ACI_TX_DATA_T_PIPE_NUMBER) = p_aci_cmd_params_send_data_t->tx_data.pipe_number;
|
||||
memcpy((buffer + OFFSET_ACI_CMD_T_SEND_DATA + OFFSET_ACI_CMD_PARAMS_SEND_DATA_T_TX_DATA + OFFSET_ACI_TX_DATA_T_ACI_DATA), &(p_aci_cmd_params_send_data_t->tx_data.aci_data[0]), data_size);
|
||||
}
|
||||
|
||||
void acil_encode_cmd_request_data(uint8_t *buffer, aci_cmd_params_request_data_t *p_aci_cmd_params_request_data)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_DATA_REQUEST_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_REQUEST_DATA;
|
||||
*(buffer + OFFSET_ACI_CMD_T_REQUEST_DATA + OFFSET_ACI_CMD_PARAMS_REQUEST_DATA_T_PIPE_NUMBER) = p_aci_cmd_params_request_data->pipe_number;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_open_remote_pipe(uint8_t *buffer, aci_cmd_params_open_remote_pipe_t *p_aci_cmd_params_open_remote_pipe)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_OPEN_REMOTE_PIPE_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_OPEN_REMOTE_PIPE;
|
||||
*(buffer + OFFSET_ACI_CMD_T_OPEN_REMOTE_PIPE + OFFSET_ACI_CMD_PARAMS_OPEN_REMOTE_PIPE_T_PIPE_NUMBER) = p_aci_cmd_params_open_remote_pipe->pipe_number;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_close_remote_pipe(uint8_t *buffer, aci_cmd_params_close_remote_pipe_t *p_aci_cmd_params_close_remote_pipe)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_CLOSE_REMOTE_PIPE_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_CLOSE_REMOTE_PIPE;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CLOSE_REMOTE_PIPE + OFFSET_ACI_CMD_PARAMS_CLOSE_REMOTE_PIPE_T_PIPE_NUMBER) = p_aci_cmd_params_close_remote_pipe->pipe_number;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_echo_msg(uint8_t *buffer, aci_cmd_params_echo_t *p_cmd_params_echo, uint8_t msg_size)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_ECHO_MSG_CMD_BASE_LEN + msg_size;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_ECHO;
|
||||
memcpy((buffer + OFFSET_ACI_CMD_T_ECHO + OFFSET_ACI_CMD_PARAMS_ECHO_T_ECHO_DATA), &(p_cmd_params_echo->echo_data[0]), msg_size);
|
||||
}
|
||||
|
||||
void acil_encode_cmd_battery_level(uint8_t *buffer)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = 1;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_GET_BATTERY_LEVEL;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_temparature(uint8_t *buffer)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = 1;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_GET_TEMPERATURE;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_read_dynamic_data(uint8_t *buffer)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = 1;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_READ_DYNAMIC_DATA;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_write_dynamic_data(uint8_t *buffer, uint8_t seq_no, uint8_t* dynamic_data, uint8_t dynamic_data_size)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_WRITE_DYNAMIC_DATA_BASE_LEN + dynamic_data_size;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_WRITE_DYNAMIC_DATA;
|
||||
*(buffer + OFFSET_ACI_CMD_T_WRITE_DYNAMIC_DATA + OFFSET_ACI_CMD_PARAMS_WRITE_DYNAMIC_DATA_T_SEQ_NO) = seq_no;
|
||||
memcpy((buffer + OFFSET_ACI_CMD_T_WRITE_DYNAMIC_DATA + OFFSET_ACI_CMD_PARAMS_WRITE_DYNAMIC_DATA_T_DYNAMIC_DATA), dynamic_data, dynamic_data_size);
|
||||
}
|
||||
|
||||
void acil_encode_cmd_change_timing_req(uint8_t *buffer, aci_cmd_params_change_timing_t *p_aci_cmd_params_change_timing)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_CHANGE_TIMING_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_CHANGE_TIMING;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CHANGE_TIMING + OFFSET_ACI_CMD_PARAMS_CHANGE_TIMING_T_CONN_PARAMS + OFFSET_ACI_LL_CONN_PARAMS_T_MIN_CONN_INTERVAL_MSB) = (uint8_t)(p_aci_cmd_params_change_timing->conn_params.min_conn_interval >> 8);
|
||||
*(buffer + OFFSET_ACI_CMD_T_CHANGE_TIMING + OFFSET_ACI_CMD_PARAMS_CHANGE_TIMING_T_CONN_PARAMS + OFFSET_ACI_LL_CONN_PARAMS_T_MIN_CONN_INTERVAL_LSB) = (uint8_t)(p_aci_cmd_params_change_timing->conn_params.min_conn_interval);
|
||||
*(buffer + OFFSET_ACI_CMD_T_CHANGE_TIMING + OFFSET_ACI_CMD_PARAMS_CHANGE_TIMING_T_CONN_PARAMS + OFFSET_ACI_LL_CONN_PARAMS_T_MAX_CONN_INTERVAL_MSB) = (uint8_t)(p_aci_cmd_params_change_timing->conn_params.max_conn_interval >> 8);
|
||||
*(buffer + OFFSET_ACI_CMD_T_CHANGE_TIMING + OFFSET_ACI_CMD_PARAMS_CHANGE_TIMING_T_CONN_PARAMS + OFFSET_ACI_LL_CONN_PARAMS_T_MAX_CONN_INTERVAL_LSB) = (uint8_t)(p_aci_cmd_params_change_timing->conn_params.max_conn_interval);
|
||||
*(buffer + OFFSET_ACI_CMD_T_CHANGE_TIMING + OFFSET_ACI_CMD_PARAMS_CHANGE_TIMING_T_CONN_PARAMS + OFFSET_ACI_LL_CONN_PARAMS_T_SLAVE_LATENCY_MSB ) = (uint8_t)(p_aci_cmd_params_change_timing->conn_params.slave_latency >> 8);
|
||||
*(buffer + OFFSET_ACI_CMD_T_CHANGE_TIMING + OFFSET_ACI_CMD_PARAMS_CHANGE_TIMING_T_CONN_PARAMS + OFFSET_ACI_LL_CONN_PARAMS_T_SLAVE_LATENCY_LSB ) = (uint8_t)(p_aci_cmd_params_change_timing->conn_params.slave_latency);
|
||||
*(buffer + OFFSET_ACI_CMD_T_CHANGE_TIMING + OFFSET_ACI_CMD_PARAMS_CHANGE_TIMING_T_CONN_PARAMS + OFFSET_ACI_LL_CONN_PARAMS_T_TIMEOUT_MULT_MSB ) = (uint8_t)(p_aci_cmd_params_change_timing->conn_params.timeout_mult >> 8);
|
||||
*(buffer + OFFSET_ACI_CMD_T_CHANGE_TIMING + OFFSET_ACI_CMD_PARAMS_CHANGE_TIMING_T_CONN_PARAMS + OFFSET_ACI_LL_CONN_PARAMS_T_TIMEOUT_MULT_LSB ) = (uint8_t)(p_aci_cmd_params_change_timing->conn_params.timeout_mult);
|
||||
}
|
||||
|
||||
void acil_encode_cmd_set_app_latency(uint8_t *buffer, aci_cmd_params_set_app_latency_t *p_aci_cmd_params_set_app_latency)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_SET_APP_LATENCY_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_SET_APP_LATENCY;
|
||||
*(buffer + OFFSET_ACI_CMD_T_SET_APP_LATENCY + OFFSET_ACI_CMD_PARAMS_SET_APP_LATENCY_T_MODE) = (uint8_t)( p_aci_cmd_params_set_app_latency->mode);
|
||||
*(buffer + OFFSET_ACI_CMD_T_SET_APP_LATENCY + OFFSET_ACI_CMD_PARAMS_SET_APP_LATENCY_T_LATENCY_MSB) = (uint8_t)( p_aci_cmd_params_set_app_latency->latency>>8);
|
||||
*(buffer + OFFSET_ACI_CMD_T_SET_APP_LATENCY + OFFSET_ACI_CMD_PARAMS_SET_APP_LATENCY_T_LATENCY_LSB) = (uint8_t)( p_aci_cmd_params_set_app_latency->latency);
|
||||
}
|
||||
|
||||
void acil_encode_cmd_change_timing_req_GAP_PPCP(uint8_t *buffer)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_CHANGE_TIMING_LEN_GAP_PPCP;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_CHANGE_TIMING;
|
||||
}
|
||||
|
||||
|
||||
void acil_encode_cmd_setup(uint8_t *buffer, aci_cmd_params_setup_t *p_aci_cmd_params_setup, uint8_t setup_data_size)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = setup_data_size + MSG_SETUP_CMD_BASE_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_SETUP;
|
||||
memcpy((buffer + OFFSET_ACI_CMD_T_SETUP), &(p_aci_cmd_params_setup->setup_data[0]), setup_data_size);
|
||||
}
|
||||
|
||||
void acil_encode_cmd_dtm_cmd(uint8_t *buffer, aci_cmd_params_dtm_cmd_t *p_aci_cmd_params_dtm_cmd)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_DTM_CMD;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_DTM_CMD;
|
||||
*(buffer + OFFSET_ACI_CMD_T_DTM_CMD) = p_aci_cmd_params_dtm_cmd->cmd_msb;
|
||||
*(buffer + OFFSET_ACI_CMD_T_DTM_CMD + 1) = p_aci_cmd_params_dtm_cmd->cmd_lsb;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_send_data_ack(uint8_t *buffer, const uint8_t pipe_number )
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_ACK_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_SEND_DATA_ACK;
|
||||
*(buffer + OFFSET_ACI_CMD_T_SEND_DATA_ACK + OFFSET_ACI_CMD_PARAMS_SEND_DATA_ACK_T_PIPE_NUMBER) = pipe_number;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_send_data_nack(uint8_t *buffer, const uint8_t pipe_number, const uint8_t err_code )
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_NACK_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_SEND_DATA_NACK;
|
||||
*(buffer + OFFSET_ACI_CMD_T_SEND_DATA_NACK + OFFSET_ACI_CMD_PARAMS_SEND_DATA_NACK_T_PIPE_NUMBER) = pipe_number;
|
||||
*(buffer + OFFSET_ACI_CMD_T_SEND_DATA_NACK + OFFSET_ACI_CMD_PARAMS_SEND_DATA_NACK_T_ERROR_CODE) = err_code;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_bond_security_request(uint8_t *buffer)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = 1;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_BOND_SECURITY_REQUEST;
|
||||
}
|
||||
|
||||
void acil_encode_cmd_broadcast(uint8_t *buffer, aci_cmd_params_broadcast_t * p_aci_cmd_params_broadcast)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_BROADCAST_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_BROADCAST;
|
||||
*(buffer + OFFSET_ACI_CMD_T_BROADCAST + OFFSET_ACI_CMD_PARAMS_BROADCAST_T_TIMEOUT_LSB) = (p_aci_cmd_params_broadcast->timeout & 0xff);
|
||||
*(buffer + OFFSET_ACI_CMD_T_BROADCAST + OFFSET_ACI_CMD_PARAMS_BROADCAST_T_TIMEOUT_MSB) = (uint8_t)(p_aci_cmd_params_broadcast->timeout >> 8);
|
||||
*(buffer + OFFSET_ACI_CMD_T_BROADCAST + OFFSET_ACI_CMD_PARAMS_BROADCAST_T_ADV_INTERVAL_LSB) = (p_aci_cmd_params_broadcast->adv_interval & 0xff);
|
||||
*(buffer + OFFSET_ACI_CMD_T_BROADCAST + OFFSET_ACI_CMD_PARAMS_BROADCAST_T_ADV_INTERVAL_MSB) = (uint8_t)(p_aci_cmd_params_broadcast->adv_interval >> 8);
|
||||
}
|
||||
|
||||
void acil_encode_cmd_open_adv_pipes(uint8_t *buffer, aci_cmd_params_open_adv_pipe_t * p_aci_cmd_params_open_adv_pipe)
|
||||
{
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = MSG_OPEN_ADV_PIPES_LEN;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_OPEN_ADV_PIPE;
|
||||
memcpy(buffer + OFFSET_ACI_CMD_T_OPEN_ADV_PIPE + OFFSET_ACI_CMD_PARAMS_OPEN_ADV_PIPE_T_PIPES, p_aci_cmd_params_open_adv_pipe->pipes, 8);
|
||||
}
|
||||
|
||||
|
||||
void acil_encode_cmd_set_key(uint8_t *buffer, aci_cmd_params_set_key_t *p_aci_cmd_params_set_key)
|
||||
{
|
||||
/*
|
||||
The length of the key is computed based on the type of key transaction.
|
||||
- Key Reject
|
||||
- Key type is passkey
|
||||
*/
|
||||
uint8_t len;
|
||||
|
||||
switch (p_aci_cmd_params_set_key->key_type)
|
||||
{
|
||||
case ACI_KEY_TYPE_INVALID:
|
||||
len = MSG_SET_KEY_REJECT_LEN;
|
||||
break;
|
||||
case ACI_KEY_TYPE_PASSKEY:
|
||||
len = MSG_SET_KEY_PASSKEY_LEN;
|
||||
break;
|
||||
default:
|
||||
len=0;
|
||||
break;
|
||||
}
|
||||
*(buffer + OFFSET_ACI_CMD_T_LEN) = len;
|
||||
*(buffer + OFFSET_ACI_CMD_T_CMD_OPCODE) = ACI_CMD_SET_KEY;
|
||||
*(buffer + OFFSET_ACI_CMD_T_SET_KEY + OFFSET_ACI_CMD_PARAMS_SET_KEY_T_KEY_TYPE) = p_aci_cmd_params_set_key->key_type;
|
||||
memcpy((buffer + OFFSET_ACI_CMD_T_SET_KEY + OFFSET_ACI_CMD_PARAMS_SET_KEY_T_PASSKEY), (uint8_t * )&(p_aci_cmd_params_set_key->key), len-2);//Reducing 2 for the opcode byte and type
|
||||
}
|
||||
|
||||
bool acil_encode_cmd(uint8_t *buffer, aci_cmd_t *p_aci_cmd)
|
||||
{
|
||||
bool ret_val = false;
|
||||
|
||||
switch(p_aci_cmd->cmd_opcode)
|
||||
{
|
||||
case ACI_CMD_TEST:
|
||||
acil_encode_cmd_set_test_mode(buffer, &(p_aci_cmd->params.test));
|
||||
break;
|
||||
case ACI_CMD_SLEEP:
|
||||
acil_encode_cmd_sleep(buffer);
|
||||
break;
|
||||
case ACI_CMD_GET_DEVICE_VERSION:
|
||||
acil_encode_cmd_get_device_version(buffer);
|
||||
break;
|
||||
case ACI_CMD_WAKEUP:
|
||||
acil_encode_cmd_wakeup(buffer);
|
||||
break;
|
||||
case ACI_CMD_ECHO:
|
||||
acil_encode_cmd_echo_msg(buffer, &(p_aci_cmd->params.echo), (p_aci_cmd->len - MSG_ECHO_MSG_CMD_BASE_LEN));
|
||||
break;
|
||||
case ACI_CMD_GET_BATTERY_LEVEL:
|
||||
acil_encode_cmd_battery_level(buffer);
|
||||
break;
|
||||
case ACI_CMD_GET_TEMPERATURE:
|
||||
acil_encode_cmd_temparature(buffer);
|
||||
break;
|
||||
case ACI_CMD_GET_DEVICE_ADDRESS:
|
||||
acil_encode_cmd_get_address(buffer);
|
||||
break;
|
||||
case ACI_CMD_SET_TX_POWER:
|
||||
acil_encode_cmd_set_radio_tx_power(buffer, &(p_aci_cmd->params.set_tx_power));
|
||||
break;
|
||||
case ACI_CMD_CONNECT:
|
||||
acil_encode_cmd_connect(buffer, &(p_aci_cmd->params.connect));
|
||||
break;
|
||||
case ACI_CMD_BOND:
|
||||
acil_encode_cmd_bond(buffer, &(p_aci_cmd->params.bond));
|
||||
break;
|
||||
case ACI_CMD_DISCONNECT:
|
||||
acil_encode_cmd_disconnect(buffer, &(p_aci_cmd->params.disconnect));
|
||||
break;
|
||||
case ACI_CMD_RADIO_RESET:
|
||||
acil_encode_baseband_reset(buffer);
|
||||
break;
|
||||
case ACI_CMD_CHANGE_TIMING:
|
||||
acil_encode_cmd_change_timing_req(buffer, &(p_aci_cmd->params.change_timing));
|
||||
break;
|
||||
case ACI_CMD_SETUP:
|
||||
acil_encode_cmd_setup(buffer, &(p_aci_cmd->params.setup), (p_aci_cmd->len - MSG_SETUP_CMD_BASE_LEN));
|
||||
break;
|
||||
case ACI_CMD_DTM_CMD:
|
||||
acil_encode_cmd_dtm_cmd(buffer, &(p_aci_cmd->params.dtm_cmd));
|
||||
break;
|
||||
case ACI_CMD_READ_DYNAMIC_DATA:
|
||||
acil_encode_cmd_read_dynamic_data(buffer);
|
||||
break;
|
||||
case ACI_CMD_WRITE_DYNAMIC_DATA:
|
||||
acil_encode_cmd_write_dynamic_data(buffer, p_aci_cmd->params.write_dynamic_data.seq_no, &(p_aci_cmd->params.write_dynamic_data.dynamic_data[0]), (p_aci_cmd->len - MSG_WRITE_DYNAMIC_DATA_BASE_LEN));
|
||||
break;
|
||||
case ACI_CMD_OPEN_REMOTE_PIPE:
|
||||
acil_encode_cmd_open_remote_pipe(buffer, &(p_aci_cmd->params.open_remote_pipe));
|
||||
break;
|
||||
case ACI_CMD_SEND_DATA:
|
||||
acil_encode_cmd_send_data(buffer, &(p_aci_cmd->params.send_data), (p_aci_cmd->len - MSG_SEND_DATA_BASE_LEN));
|
||||
break;
|
||||
case ACI_CMD_SEND_DATA_ACK:
|
||||
acil_encode_cmd_send_data_ack(buffer, p_aci_cmd->params.send_data_ack.pipe_number );
|
||||
break;
|
||||
case ACI_CMD_REQUEST_DATA:
|
||||
acil_encode_cmd_request_data(buffer, &(p_aci_cmd->params.request_data));
|
||||
break;
|
||||
case ACI_CMD_SET_LOCAL_DATA:
|
||||
acil_encode_cmd_set_local_data(buffer, (aci_cmd_params_set_local_data_t *)(&(p_aci_cmd->params.send_data)), (p_aci_cmd->len - MSG_SET_LOCAL_DATA_BASE_LEN));
|
||||
break;
|
||||
case ACI_CMD_BOND_SECURITY_REQUEST:
|
||||
acil_encode_cmd_bond_security_request(buffer);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
void acil_decode_evt_command_response(uint8_t *buffer_in, aci_evt_params_cmd_rsp_t *p_evt_params_cmd_rsp)
|
||||
{
|
||||
aci_evt_cmd_rsp_params_get_device_version_t *p_device_version;
|
||||
aci_evt_cmd_rsp_params_get_device_address_t *p_device_address;
|
||||
aci_evt_cmd_rsp_params_get_temperature_t *p_temperature;
|
||||
aci_evt_cmd_rsp_params_get_battery_level_t *p_batt_lvl;
|
||||
aci_evt_cmd_rsp_read_dynamic_data_t *p_read_dyn_data;
|
||||
aci_evt_cmd_rsp_params_dtm_cmd_t *p_dtm_evt;
|
||||
|
||||
p_evt_params_cmd_rsp->cmd_opcode = (aci_cmd_opcode_t)*(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_CMD_OPCODE);
|
||||
p_evt_params_cmd_rsp->cmd_status = (aci_status_code_t)*(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_CMD_STATUS);
|
||||
|
||||
switch (p_evt_params_cmd_rsp->cmd_opcode)
|
||||
{
|
||||
case ACI_CMD_GET_DEVICE_VERSION:
|
||||
p_device_version = &(p_evt_params_cmd_rsp->params.get_device_version);
|
||||
p_device_version->configuration_id = (uint16_t)*(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_DEVICE_VERSION + OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_CONFIGURATION_ID_LSB);
|
||||
p_device_version->configuration_id |= (uint16_t)*(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_DEVICE_VERSION + OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_CONFIGURATION_ID_MSB) << 8;
|
||||
p_device_version->aci_version = *(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_DEVICE_VERSION + OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_ACI_VERSION);
|
||||
p_device_version->setup_format = *(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_DEVICE_VERSION + OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_FORMAT);
|
||||
p_device_version->setup_id = (uint32_t)*(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_DEVICE_VERSION + OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_ID_LSB0);
|
||||
p_device_version->setup_id |= (uint32_t)*(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_DEVICE_VERSION + OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_ID_LSB1) << 8;
|
||||
p_device_version->setup_id |= (uint32_t)*(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_DEVICE_VERSION + OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_ID_MSB0) << 16;
|
||||
p_device_version->setup_id |= (uint32_t)*(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_DEVICE_VERSION + OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_ID_MSB1) << 24;
|
||||
p_device_version->setup_status = *(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_DEVICE_VERSION + OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_VERSION_T_SETUP_STATUS);
|
||||
break;
|
||||
|
||||
case ACI_CMD_GET_DEVICE_ADDRESS:
|
||||
p_device_address = &(p_evt_params_cmd_rsp->params.get_device_address);
|
||||
memcpy((uint8_t *)(p_device_address->bd_addr_own), (buffer_in + OFFSET_ACI_EVT_T_CMD_RSP+OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_DEVICE_ADDRESS+OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_ADDRESS_T_BD_ADDR_OWN), BTLE_DEVICE_ADDRESS_SIZE);
|
||||
p_device_address->bd_addr_type = (aci_bd_addr_type_t) *(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP+OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_DEVICE_ADDRESS+OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_DEVICE_ADDRESS_T_BD_ADDR_TYPE);
|
||||
break;
|
||||
|
||||
case ACI_CMD_GET_TEMPERATURE:
|
||||
p_temperature = &(p_evt_params_cmd_rsp->params.get_temperature);
|
||||
p_temperature->temperature_value = (int16_t)*(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_TEMPERATURE + OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_TEMPERATURE_T_TEMPERATURE_VALUE_LSB);
|
||||
p_temperature->temperature_value |= (int16_t)*(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_TEMPERATURE + OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_TEMPERATURE_T_TEMPERATURE_VALUE_MSB) << 8;
|
||||
break;
|
||||
|
||||
case ACI_CMD_GET_BATTERY_LEVEL:
|
||||
p_batt_lvl = &(p_evt_params_cmd_rsp->params.get_battery_level);
|
||||
p_batt_lvl->battery_level = (int16_t)*(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_BATTERY_LEVEL + OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_BATTERY_LEVEL_T_BATTERY_LEVEL_LSB);
|
||||
p_batt_lvl->battery_level |= (int16_t)*(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_GET_BATTERY_LEVEL + OFFSET_ACI_EVT_CMD_RSP_PARAMS_GET_BATTERY_LEVEL_T_BATTERY_LEVEL_MSB) << 8;
|
||||
break;
|
||||
|
||||
case ACI_CMD_READ_DYNAMIC_DATA:
|
||||
p_read_dyn_data = &(p_evt_params_cmd_rsp->params.read_dynamic_data);
|
||||
p_read_dyn_data->seq_no = (uint8_t)*(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_READ_DYNAMIC_DATA + OFFSET_ACI_EVT_CMD_RSP_READ_DYNAMIC_DATA_T_SEQ_NO);
|
||||
memcpy((uint8_t *)(p_read_dyn_data->dynamic_data), (buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_READ_DYNAMIC_DATA + OFFSET_ACI_CMD_PARAMS_WRITE_DYNAMIC_DATA_T_DYNAMIC_DATA), ACIL_DECODE_EVT_GET_LENGTH(buffer_in) - 3); // 3 bytes subtracted account for EventCode, CommandOpCode and Status bytes.
|
||||
// Now that the p_read_dyn_data->dynamic_data will be pointing to memory location with enough space to accommodate upto 27 bytes of dynamic data received. This is because of the padding element in aci_evt_params_cmd_rsp_t
|
||||
break;
|
||||
|
||||
case ACI_CMD_DTM_CMD:
|
||||
p_dtm_evt = &(p_evt_params_cmd_rsp->params.dtm_cmd);
|
||||
p_dtm_evt->evt_msb = (uint8_t)*(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_DTM_CMD + OFFSET_ACI_EVT_CMD_RSP_PARAMS_DTM_CMD_T_EVT_MSB);
|
||||
p_dtm_evt->evt_lsb = (uint8_t)*(buffer_in + OFFSET_ACI_EVT_T_CMD_RSP + OFFSET_ACI_EVT_PARAMS_CMD_RSP_T_DTM_CMD + OFFSET_ACI_EVT_CMD_RSP_PARAMS_DTM_CMD_T_EVT_LSB);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void acil_decode_evt_device_started(uint8_t *buffer_in, aci_evt_params_device_started_t *p_evt_params_device_started)
|
||||
{
|
||||
p_evt_params_device_started->device_mode = (aci_device_operation_mode_t) *(buffer_in + OFFSET_ACI_EVT_T_DEVICE_STARTED+OFFSET_ACI_EVT_PARAMS_DEVICE_STARTED_T_DEVICE_MODE);
|
||||
p_evt_params_device_started->hw_error = (aci_hw_error_t) *(buffer_in + OFFSET_ACI_EVT_T_DEVICE_STARTED+OFFSET_ACI_EVT_PARAMS_DEVICE_STARTED_T_HW_ERROR);
|
||||
p_evt_params_device_started->credit_available = *(buffer_in + OFFSET_ACI_EVT_T_DEVICE_STARTED+OFFSET_ACI_EVT_PARAMS_DEVICE_STARTED_T_CREDIT_AVAILABLE);
|
||||
}
|
||||
|
||||
void acil_decode_evt_pipe_status(uint8_t *buffer_in, aci_evt_params_pipe_status_t *p_aci_evt_params_pipe_status)
|
||||
{
|
||||
memcpy((uint8_t *)p_aci_evt_params_pipe_status->pipes_open_bitmap, (buffer_in + OFFSET_ACI_EVT_T_PIPE_STATUS + OFFSET_ACI_EVT_PARAMS_PIPE_STATUS_T_PIPES_OPEN_BITMAP), 8);
|
||||
memcpy((uint8_t *)p_aci_evt_params_pipe_status->pipes_closed_bitmap, (buffer_in + OFFSET_ACI_EVT_T_PIPE_STATUS + OFFSET_ACI_EVT_PARAMS_PIPE_STATUS_T_PIPES_CLOSED_BITMAP), 8);
|
||||
}
|
||||
|
||||
void acil_decode_evt_disconnected(uint8_t *buffer_in, aci_evt_params_disconnected_t *p_aci_evt_params_disconnected)
|
||||
{
|
||||
p_aci_evt_params_disconnected->aci_status = (aci_status_code_t)*(buffer_in + OFFSET_ACI_EVT_T_DISCONNECTED + OFFSET_ACI_EVT_PARAMS_DISCONNECTED_T_ACI_STATUS);
|
||||
p_aci_evt_params_disconnected->btle_status = *(buffer_in + OFFSET_ACI_EVT_T_DISCONNECTED + OFFSET_ACI_EVT_PARAMS_DISCONNECTED_T_BTLE_STATUS);
|
||||
}
|
||||
|
||||
void acil_decode_evt_bond_status(uint8_t *buffer_in, aci_evt_params_bond_status_t *p_aci_evt_params_bond_status)
|
||||
{
|
||||
p_aci_evt_params_bond_status->status_code = (aci_bond_status_code_t)*(buffer_in + OFFSET_ACI_EVT_T_BOND_STATUS + OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_STATUS_CODE);
|
||||
p_aci_evt_params_bond_status->status_source = (aci_bond_status_source_t)*(buffer_in + OFFSET_ACI_EVT_T_BOND_STATUS + OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_STATUS_SOURCE);
|
||||
p_aci_evt_params_bond_status->secmode1_bitmap = *(buffer_in + OFFSET_ACI_EVT_T_BOND_STATUS + OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_SECMODE1_BITMAP);
|
||||
p_aci_evt_params_bond_status->secmode2_bitmap = *(buffer_in + OFFSET_ACI_EVT_T_BOND_STATUS + OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_SECMODE2_BITMAP);
|
||||
p_aci_evt_params_bond_status->keys_exchanged_slave = *(buffer_in + OFFSET_ACI_EVT_T_BOND_STATUS + OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_KEYS_EXCHANGED_SLAVE);
|
||||
p_aci_evt_params_bond_status->keys_exchanged_master = *(buffer_in + OFFSET_ACI_EVT_T_BOND_STATUS + OFFSET_ACI_EVT_PARAMS_BOND_STATUS_T_KEYS_EXCHANGED_MASTER);
|
||||
}
|
||||
|
||||
uint8_t acil_decode_evt_data_received(uint8_t *buffer_in, aci_evt_params_data_received_t *p_evt_params_data_received)
|
||||
{
|
||||
uint8_t size = *( buffer_in + OFFSET_ACI_EVT_T_LEN) - (OFFSET_ACI_EVT_T_DATA_RECEIVED + OFFSET_ACI_RX_DATA_T_ACI_DATA) + 1 ;
|
||||
p_evt_params_data_received->rx_data.pipe_number = *(buffer_in + OFFSET_ACI_EVT_T_DATA_RECEIVED + OFFSET_ACI_RX_DATA_T_PIPE_NUMBER);
|
||||
memcpy((uint8_t *)p_evt_params_data_received->rx_data.aci_data, (buffer_in + OFFSET_ACI_EVT_T_DATA_RECEIVED + OFFSET_ACI_RX_DATA_T_ACI_DATA), size);
|
||||
return size;
|
||||
}
|
||||
|
||||
void acil_decode_evt_data_ack(uint8_t *buffer_in, aci_evt_params_data_ack_t *p_evt_params_data_ack)
|
||||
{
|
||||
p_evt_params_data_ack->pipe_number = *(buffer_in + OFFSET_ACI_EVT_T_DATA_ACK + OFFSET_ACI_EVT_PARAMS_DATA_ACK_T_PIPE_NUMBER);
|
||||
}
|
||||
|
||||
uint8_t acil_decode_evt_hw_error(uint8_t *buffer_in, aci_evt_params_hw_error_t *p_aci_evt_params_hw_error)
|
||||
{
|
||||
uint8_t size = *(buffer_in + OFFSET_ACI_EVT_T_LEN) - (OFFSET_ACI_EVT_T_HW_ERROR + OFFSET_ACI_EVT_PARAMS_HW_ERROR_T_FILE_NAME) + 1;
|
||||
p_aci_evt_params_hw_error->line_num = (uint16_t)(*(buffer_in + OFFSET_ACI_EVT_T_HW_ERROR + OFFSET_ACI_EVT_PARAMS_HW_ERROR_T_LINE_NUM_MSB)) << 8;
|
||||
p_aci_evt_params_hw_error->line_num |= (uint16_t)*(buffer_in + OFFSET_ACI_EVT_T_HW_ERROR + OFFSET_ACI_EVT_PARAMS_HW_ERROR_T_LINE_NUM_LSB);
|
||||
memcpy((uint8_t *)p_aci_evt_params_hw_error->file_name, (buffer_in + OFFSET_ACI_EVT_T_HW_ERROR + OFFSET_ACI_EVT_PARAMS_HW_ERROR_T_FILE_NAME), size);
|
||||
return size;
|
||||
}
|
||||
|
||||
void acil_decode_evt_credit(uint8_t *buffer_in, aci_evt_params_data_credit_t *p_evt_params_data_credit)
|
||||
{
|
||||
p_evt_params_data_credit->credit = *(buffer_in + OFFSET_ACI_EVT_T_DATA_CREDIT + OFFSET_ACI_EVT_PARAMS_DATA_CREDIT_T_CREDIT);
|
||||
}
|
||||
|
||||
void acil_decode_evt_connected(uint8_t *buffer_in, aci_evt_params_connected_t *p_aci_evt_params_connected)
|
||||
{
|
||||
p_aci_evt_params_connected->dev_addr_type = (aci_bd_addr_type_t)*(buffer_in + OFFSET_ACI_EVT_T_CONNECTED + OFFSET_ACI_EVT_PARAMS_CONNECTED_T_DEV_ADDR_TYPE);
|
||||
memcpy(&(p_aci_evt_params_connected->dev_addr[0]), (buffer_in + OFFSET_ACI_EVT_T_CONNECTED + OFFSET_ACI_EVT_PARAMS_CONNECTED_T_DEV_ADDR), BTLE_DEVICE_ADDRESS_SIZE);
|
||||
p_aci_evt_params_connected->conn_rf_interval = (uint16_t)*(buffer_in + OFFSET_ACI_EVT_T_CONNECTED + OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_RF_INTERVAL_MSB) << 8;
|
||||
p_aci_evt_params_connected->conn_rf_interval |= (uint16_t)*(buffer_in + OFFSET_ACI_EVT_T_CONNECTED + OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_RF_INTERVAL_LSB);
|
||||
p_aci_evt_params_connected->conn_slave_rf_latency = (uint16_t)*(buffer_in + OFFSET_ACI_EVT_T_CONNECTED + OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_SLAVE_RF_LATENCY_MSB) << 8;
|
||||
p_aci_evt_params_connected->conn_slave_rf_latency |= (uint16_t)*(buffer_in + OFFSET_ACI_EVT_T_CONNECTED + OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_SLAVE_RF_LATENCY_LSB);
|
||||
p_aci_evt_params_connected->conn_rf_timeout = (uint16_t)*(buffer_in + OFFSET_ACI_EVT_T_CONNECTED + OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_RF_TIMEOUT_MSB) << 8;
|
||||
p_aci_evt_params_connected->conn_rf_timeout |= (uint16_t)*(buffer_in + OFFSET_ACI_EVT_T_CONNECTED + OFFSET_ACI_EVT_PARAMS_CONNECTED_T_CONN_RF_TIMEOUT_LSB);
|
||||
p_aci_evt_params_connected->master_clock_accuracy = (aci_clock_accuracy_t)*(buffer_in + OFFSET_ACI_EVT_T_CONNECTED + OFFSET_ACI_EVT_PARAMS_CONNECTED_T_MASTER_CLOCK_ACCURACY);
|
||||
|
||||
}
|
||||
|
||||
void acil_decode_evt_timing(uint8_t *buffer_in, aci_evt_params_timing_t *p_evt_params_timing)
|
||||
{
|
||||
p_evt_params_timing->conn_rf_interval = *(buffer_in + OFFSET_ACI_EVT_T_TIMING + OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_RF_INTERVAL_MSB) << 8;
|
||||
p_evt_params_timing->conn_rf_interval |= (uint16_t)*(buffer_in + OFFSET_ACI_EVT_T_TIMING + OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_RF_INTERVAL_LSB);
|
||||
p_evt_params_timing->conn_slave_rf_latency = (uint16_t)*(buffer_in + OFFSET_ACI_EVT_T_TIMING + OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_SLAVE_RF_LATENCY_MSB) << 8;
|
||||
p_evt_params_timing->conn_slave_rf_latency |= (uint16_t)*(buffer_in + OFFSET_ACI_EVT_T_TIMING + OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_SLAVE_RF_LATENCY_LSB);
|
||||
p_evt_params_timing->conn_rf_timeout = (uint16_t)*(buffer_in + OFFSET_ACI_EVT_T_TIMING + OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_RF_TIMEOUT_MSB) << 8;
|
||||
p_evt_params_timing->conn_rf_timeout |= *(buffer_in + OFFSET_ACI_EVT_T_TIMING + OFFSET_ACI_EVT_PARAMS_TIMING_T_CONN_RF_TIMEOUT_LSB);
|
||||
}
|
||||
|
||||
void acil_decode_evt_pipe_error(uint8_t *buffer_in, aci_evt_params_pipe_error_t *p_evt_params_pipe_error)
|
||||
{
|
||||
//volatile uint8_t size = *(buffer_in + OFFSET_ACI_EVT_T_LEN) - (OFFSET_ACI_EVT_T_PIPE_ERROR + OFFSET_ACI_EVT_PARAMS_PIPE_ERROR_T_ERROR_DATA) + 1;
|
||||
p_evt_params_pipe_error->pipe_number = *(buffer_in + OFFSET_ACI_EVT_T_PIPE_ERROR + OFFSET_ACI_EVT_PARAMS_PIPE_ERROR_T_PIPE_NUMBER);
|
||||
p_evt_params_pipe_error->error_code = *(buffer_in + OFFSET_ACI_EVT_T_PIPE_ERROR + OFFSET_ACI_EVT_PARAMS_PIPE_ERROR_T_ERROR_CODE);
|
||||
p_evt_params_pipe_error->params.error_data.content[0] = *(buffer_in + OFFSET_ACI_EVT_T_PIPE_ERROR + OFFSET_ACI_EVT_PARAMS_PIPE_ERROR_T_ERROR_DATA + OFFSET_ERROR_DATA_T_CONTENT);
|
||||
}
|
||||
|
||||
void acil_decode_evt_key_request(uint8_t *buffer_in, aci_evt_params_key_request_t *p_evt_params_key_request)
|
||||
{
|
||||
p_evt_params_key_request->key_type = (aci_key_type_t)*(buffer_in + OFFSET_ACI_EVT_T_KEY_REQUEST + OFFSET_ACI_EVT_PARAMS_KEY_REQUEST_T_KEY_TYPE);
|
||||
}
|
||||
|
||||
uint8_t acil_decode_evt_echo(uint8_t *buffer_in, aci_evt_params_echo_t *aci_evt_params_echo)
|
||||
{
|
||||
uint8_t size = *(buffer_in + OFFSET_ACI_EVT_T_LEN) - 1;
|
||||
memcpy(&aci_evt_params_echo->echo_data[0], (buffer_in + OFFSET_ACI_EVT_T_EVT_OPCODE + 1), size);
|
||||
return size;
|
||||
}
|
||||
|
||||
void acil_decode_evt_display_passkey(uint8_t *buffer_in, aci_evt_params_display_passkey_t *p_aci_evt_params_display_passkey)
|
||||
{
|
||||
p_aci_evt_params_display_passkey->passkey[0] = *(buffer_in + OFFSET_ACI_EVT_T_DISPLAY_PASSKEY + OFFSET_ACI_EVT_PARAMS_DISPLAY_PASSKEY_T_PASSKEY + 0);
|
||||
p_aci_evt_params_display_passkey->passkey[1] = *(buffer_in + OFFSET_ACI_EVT_T_DISPLAY_PASSKEY + OFFSET_ACI_EVT_PARAMS_DISPLAY_PASSKEY_T_PASSKEY + 1);
|
||||
p_aci_evt_params_display_passkey->passkey[2] = *(buffer_in + OFFSET_ACI_EVT_T_DISPLAY_PASSKEY + OFFSET_ACI_EVT_PARAMS_DISPLAY_PASSKEY_T_PASSKEY + 2);
|
||||
p_aci_evt_params_display_passkey->passkey[3] = *(buffer_in + OFFSET_ACI_EVT_T_DISPLAY_PASSKEY + OFFSET_ACI_EVT_PARAMS_DISPLAY_PASSKEY_T_PASSKEY + 3);
|
||||
p_aci_evt_params_display_passkey->passkey[4] = *(buffer_in + OFFSET_ACI_EVT_T_DISPLAY_PASSKEY + OFFSET_ACI_EVT_PARAMS_DISPLAY_PASSKEY_T_PASSKEY + 4);
|
||||
p_aci_evt_params_display_passkey->passkey[5] = *(buffer_in + OFFSET_ACI_EVT_T_DISPLAY_PASSKEY + OFFSET_ACI_EVT_PARAMS_DISPLAY_PASSKEY_T_PASSKEY + 5);
|
||||
}
|
||||
|
||||
bool acil_decode_evt(uint8_t *buffer_in, aci_evt_t *p_aci_evt)
|
||||
{
|
||||
bool ret_val = true;
|
||||
|
||||
p_aci_evt->len = ACIL_DECODE_EVT_GET_LENGTH(buffer_in);
|
||||
p_aci_evt->evt_opcode = (aci_evt_opcode_t)ACIL_DECODE_EVT_GET_OPCODE(buffer_in);
|
||||
|
||||
switch(p_aci_evt->evt_opcode)
|
||||
{
|
||||
case ACI_EVT_DEVICE_STARTED:
|
||||
acil_decode_evt_device_started(buffer_in, &(p_aci_evt->params.device_started));
|
||||
break;
|
||||
case ACI_EVT_HW_ERROR:
|
||||
acil_decode_evt_hw_error(buffer_in, &(p_aci_evt->params.hw_error));
|
||||
break;
|
||||
case ACI_EVT_CMD_RSP:
|
||||
acil_decode_evt_command_response(buffer_in, &(p_aci_evt->params.cmd_rsp));
|
||||
break;
|
||||
case ACI_EVT_DATA_CREDIT:
|
||||
acil_decode_evt_credit(buffer_in, &(p_aci_evt->params.data_credit));
|
||||
break;
|
||||
case ACI_EVT_CONNECTED:
|
||||
acil_decode_evt_connected(buffer_in, &(p_aci_evt->params.connected));
|
||||
break;
|
||||
case ACI_EVT_PIPE_STATUS:
|
||||
acil_decode_evt_pipe_status(buffer_in, &(p_aci_evt->params.pipe_status));
|
||||
break;
|
||||
case ACI_EVT_DISCONNECTED:
|
||||
acil_decode_evt_disconnected(buffer_in, &(p_aci_evt->params.disconnected));
|
||||
break;
|
||||
case ACI_EVT_BOND_STATUS:
|
||||
acil_decode_evt_bond_status(buffer_in, &(p_aci_evt->params.bond_status));
|
||||
break;
|
||||
case ACI_EVT_TIMING:
|
||||
acil_decode_evt_timing(buffer_in, &(p_aci_evt->params.timing));
|
||||
break;
|
||||
case ACI_EVT_DATA_ACK:
|
||||
acil_decode_evt_data_ack(buffer_in, &(p_aci_evt->params.data_ack));
|
||||
break;
|
||||
case ACI_EVT_DATA_RECEIVED:
|
||||
acil_decode_evt_data_received(buffer_in, &(p_aci_evt->params.data_received));
|
||||
break;
|
||||
case ACI_EVT_PIPE_ERROR:
|
||||
acil_decode_evt_pipe_error(buffer_in, &(p_aci_evt->params.pipe_error));
|
||||
break;
|
||||
case ACI_EVT_KEY_REQUEST:
|
||||
acil_decode_evt_key_request(buffer_in, &(p_aci_evt->params.key_request));
|
||||
break;
|
||||
case ACI_EVT_DISPLAY_PASSKEY:
|
||||
acil_decode_evt_display_passkey(buffer_in, &(p_aci_evt->params.display_passkey));
|
||||
break;
|
||||
default:
|
||||
ret_val = false;
|
||||
break;
|
||||
}
|
||||
return ret_val;
|
||||
}
|
||||
53
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/acilib.h
Executable file
53
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/acilib.h
Executable file
@@ -0,0 +1,53 @@
|
||||
/* Copyright (c) 2010 Nordic Semiconductor. All Rights Reserved.
|
||||
*
|
||||
* The information contained herein is property of Nordic Semiconductor ASA.
|
||||
* Terms and conditions of usage are described in detail in NORDIC
|
||||
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
|
||||
*
|
||||
* Licensees are granted free, non-transferable use of the information. NO
|
||||
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
|
||||
* the file.
|
||||
*
|
||||
* $LastChangedRevision$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup group_acilib
|
||||
*
|
||||
* @brief Internal prototype for acilib module.
|
||||
*/
|
||||
|
||||
#ifndef _acilib_H_
|
||||
#define _acilib_H_
|
||||
|
||||
#define MSG_SET_LOCAL_DATA_BASE_LEN 2
|
||||
#define MSG_CONNECT_LEN 5
|
||||
#define MSG_BOND_LEN 5
|
||||
#define MSG_DISCONNECT_LEN 2
|
||||
#define MSG_BASEBAND_RESET_LEN 1
|
||||
#define MSG_WAKEUP_LEN 1
|
||||
#define MSG_SET_RADIO_TX_POWER_LEN 2
|
||||
#define MSG_GET_DEVICE_ADDR_LEN 1
|
||||
#define MSG_SEND_DATA_BASE_LEN 2
|
||||
#define MSG_DATA_REQUEST_LEN 2
|
||||
#define MSG_OPEN_REMOTE_PIPE_LEN 2
|
||||
#define MSG_CLOSE_REMOTE_PIPE_LEN 2
|
||||
#define MSG_DTM_CMD 3
|
||||
#define MSG_WRITE_DYNAMIC_DATA_BASE_LEN 2
|
||||
#define MSG_SETUP_CMD_BASE_LEN 1
|
||||
#define MSG_ECHO_MSG_CMD_BASE_LEN 1
|
||||
#define MSG_CHANGE_TIMING_LEN 9
|
||||
#define MSG_SET_APP_LATENCY_LEN 4
|
||||
#define MSG_CHANGE_TIMING_LEN_GAP_PPCP 1
|
||||
#define MSG_DIRECT_CONNECT_LEN 1
|
||||
#define MSG_SET_KEY_REJECT_LEN 2
|
||||
#define MSG_SET_KEY_PASSKEY_LEN 8
|
||||
#define MSG_SET_KEY_OOB_LEN 18
|
||||
#define MSG_ACK_LEN 2
|
||||
#define MSG_NACK_LEN 3
|
||||
#define MSG_BROADCAST_LEN 5
|
||||
#define MSG_OPEN_ADV_PIPES_LEN 9
|
||||
|
||||
#endif /* _acilib_H_ */
|
||||
29
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/acilib_defs.h
Executable file
29
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/acilib_defs.h
Executable file
@@ -0,0 +1,29 @@
|
||||
/* Copyright (c) 2010 Nordic Semiconductor. All Rights Reserved.
|
||||
*
|
||||
* The information contained herein is property of Nordic Semiconductor ASA.
|
||||
* Terms and conditions of usage are described in detail in NORDIC
|
||||
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
|
||||
*
|
||||
* Licensees are granted free, non-transferable use of the information. NO
|
||||
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
|
||||
* the file.
|
||||
*
|
||||
* $LastChangedRevision$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup group_acilib
|
||||
*
|
||||
* @brief Definitions for the acilib interfaces
|
||||
*/
|
||||
|
||||
#ifndef _acilib_DEFS_H_
|
||||
#define _acilib_DEFS_H_
|
||||
|
||||
#define ACIL_DECODE_EVT_GET_LENGTH(buffer_in) (*(buffer_in + OFFSET_ACI_EVT_T_LEN))
|
||||
|
||||
#define ACIL_DECODE_EVT_GET_OPCODE(buffer_in) (*(buffer_in + OFFSET_ACI_EVT_T_EVT_OPCODE))
|
||||
|
||||
#endif /* _acilib_DEFS_H_ */
|
||||
463
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/acilib_if.h
Executable file
463
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/acilib_if.h
Executable file
@@ -0,0 +1,463 @@
|
||||
/* Copyright (c) 2010 Nordic Semiconductor. All Rights Reserved.
|
||||
*
|
||||
* The information contained herein is property of Nordic Semiconductor ASA.
|
||||
* Terms and conditions of usage are described in detail in NORDIC
|
||||
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
|
||||
*
|
||||
* Licensees are granted free, non-transferable use of the information. NO
|
||||
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
|
||||
* the file.
|
||||
*
|
||||
* $LastChangedRevision$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup group_acilib
|
||||
*
|
||||
* @brief Prototypes for the acilib interfaces.
|
||||
*/
|
||||
|
||||
#ifndef _acilib_IF_H_
|
||||
#define _acilib_IF_H_
|
||||
|
||||
/** @brief Encode the ACI message for set test mode command
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] test_mode Pointer to the test mode in ::aci_cmd_params_test_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_set_test_mode(uint8_t *buffer, aci_cmd_params_test_t *p_aci_cmd_params_test);
|
||||
|
||||
/** @brief Encode the ACI message for sleep command
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_sleep(uint8_t *buffer);
|
||||
|
||||
/** @brief Encode the ACI message for get device version
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_get_device_version(uint8_t *buffer);
|
||||
|
||||
/** @brief Encode the ACI message for set local data
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_aci_cmd_params_set_local_data Pointer to the local data parameters in ::aci_cmd_params_set_local_data_t
|
||||
* @param[in] data_size Size of data message
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_set_local_data(uint8_t *buffer, aci_cmd_params_set_local_data_t *p_aci_cmd_params_set_local_data, uint8_t data_size);
|
||||
|
||||
/** @brief Encode the ACI message to connect
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_aci_cmd_params_connect Pointer to the run parameters in ::aci_cmd_params_connect_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_connect(uint8_t *buffer, aci_cmd_params_connect_t *p_aci_cmd_params_connect);
|
||||
|
||||
/** @brief Encode the ACI message to bond
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_aci_cmd_params_bond Pointer to the run parameters in ::aci_cmd_params_bond_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_bond(uint8_t *buffer, aci_cmd_params_bond_t *p_aci_cmd_params_bond);
|
||||
|
||||
/** @brief Encode the ACI message to disconnect
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_aci_cmd_params_disconnect Pointer to the run parameters in ::aci_cmd_params_disconnect_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_disconnect(uint8_t *buffer, aci_cmd_params_disconnect_t *p_aci_cmd_params_disconnect);
|
||||
|
||||
/** @brief Encode the ACI message to baseband reset
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_baseband_reset(uint8_t *buffer);
|
||||
|
||||
/** @brief Encode the ACI message for Directed Advertising
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_direct_connect(uint8_t *buffer);
|
||||
|
||||
/** @brief Encode the ACI message to wakeup
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_wakeup(uint8_t *buffer);
|
||||
|
||||
/** @brief Encode the ACI message for set radio Tx power
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_aci_cmd_params_set_tx_power Pointer to the set Tx power parameters in ::aci_cmd_params_set_tx_power_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_set_radio_tx_power(uint8_t *buffer, aci_cmd_params_set_tx_power_t *p_aci_cmd_params_set_tx_power);
|
||||
|
||||
/** @brief Encode the ACI message for get device address
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_get_address(uint8_t *buffer);
|
||||
|
||||
/** @brief Encode the ACI message for send data
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_aci_cmd_params_send_data_t Pointer to the data parameters in ::aci_cmd_params_send_data_t
|
||||
* @param[in] data_size Size of data message
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_send_data(uint8_t *buffer, aci_cmd_params_send_data_t *p_aci_cmd_params_send_data_t, uint8_t data_size);
|
||||
|
||||
/** @brief Encode the ACI message for request data
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_aci_cmd_params_request_data Pointer to the request data parameters in ::aci_cmd_params_request_data_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_request_data(uint8_t *buffer, aci_cmd_params_request_data_t *p_aci_cmd_params_request_data);
|
||||
|
||||
/** @brief Encode the ACI message for open remote pipe
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_aci_cmd_params_open_remote_pipe Pointer to the dynamic data parameters in ::aci_cmd_params_open_remote_pipe_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_open_remote_pipe(uint8_t *buffer, aci_cmd_params_open_remote_pipe_t *p_aci_cmd_params_open_remote_pipe);
|
||||
|
||||
/** @brief Encode the ACI message for close remote pipe
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_aci_cmd_params_close_remote_pipe Pointer to the dynamic data parameters in ::aci_cmd_params_close_remote_pipe_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_close_remote_pipe(uint8_t *buffer, aci_cmd_params_close_remote_pipe_t *p_aci_cmd_params_close_remote_pipe);
|
||||
|
||||
/** @brief Encode the ACI message for echo message
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_cmd_params_echo Pointer to the dynamic data parameters in ::aci_cmd_params_echo_t
|
||||
* @param[in] msg_size Size of the message
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_echo_msg(uint8_t *buffer, aci_cmd_params_echo_t *p_cmd_params_echo, uint8_t msg_size);
|
||||
|
||||
/** @brief Encode the ACI message to battery level
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_battery_level(uint8_t *buffer);
|
||||
|
||||
/** @brief Encode the ACI message to temparature
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_temparature(uint8_t *buffer);
|
||||
|
||||
/** @brief Encode the ACI message to read dynamic data
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_read_dynamic_data(uint8_t *buffer);
|
||||
|
||||
/** @brief Encode the ACI message to change timing request
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_aci_cmd_params_change_timing Pointer to the change timing parameters in ::aci_cmd_params_change_timing_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_change_timing_req(uint8_t *buffer, aci_cmd_params_change_timing_t *p_aci_cmd_params_change_timing);
|
||||
|
||||
/** @brief Encode the ACI message to change timing request using the timing parameters from GAP PPCP
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_aci_cmd_params_change_timing Pointer to the change timing parameters in ::aci_cmd_params_change_timing_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_change_timing_req_GAP_PPCP(uint8_t *buffer);
|
||||
|
||||
|
||||
/** @brief Encode the ACI message for write dynamic data
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] seq_no Sequence number of the dynamic data (as received in the response to @c Read Dynamic Data)
|
||||
* @param[in] dynamic_data Pointer to the dynamic data
|
||||
* @param[in] dynamic_data_size Size of dynamic data
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_write_dynamic_data(uint8_t *buffer, uint8_t seq_no, uint8_t* dynamic_data, uint8_t dynamic_data_size);
|
||||
|
||||
/** @brief Encode the ACI message to send data acknowledgement
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] pipe_number Pipe number for which the ack is to be sent
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_send_data_ack(uint8_t *buffer, const uint8_t pipe_number);
|
||||
|
||||
/** @brief Encode the ACI message to send negative acknowledgement
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] pipe_number Pipe number for which the nack is to be sent
|
||||
* @param[in] error_code Error code that has to be sent in the NACK
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_send_data_nack(uint8_t *buffer, const uint8_t pipe_number,const uint8_t error_code);
|
||||
|
||||
/** @brief Encode the ACI message to set the application latency
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_aci_cmd_params_set_app_latency Pointer to the set_application_latency command parameters in ::aci_cmd_params_dtm_cmd_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_set_app_latency(uint8_t *buffer, aci_cmd_params_set_app_latency_t *p_aci_cmd_params_set_app_latency);
|
||||
|
||||
/** @brief Encode the ACI message for setup
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_cmd_params_set_run_behaviour Pointer to the setup data in ::aci_cmd_params_setup_t
|
||||
* @param[in] setup_data_size Size of setup message
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_setup(uint8_t *buffer, aci_cmd_params_setup_t *p_aci_cmd_params_setup, uint8_t setup_data_size);
|
||||
|
||||
/** @brief Encode the ACI message for DTM command
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_cmd_params_set_run_behaviour Pointer to the DTM command parameters in ::aci_cmd_params_dtm_cmd_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_dtm_cmd(uint8_t *buffer, aci_cmd_params_dtm_cmd_t *p_aci_cmd_params_dtm_cmd);
|
||||
|
||||
/** @brief Encode the ACI message for Set Key Request command
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_set_key(uint8_t *buffer, aci_cmd_params_set_key_t *p_aci_cmd_params_set_key);
|
||||
|
||||
/** @brief Encode the ACI message for Bond Security Request command
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_bond_security_request(uint8_t *buffer);
|
||||
|
||||
/** @brief Encode the ACI message
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_aci_cmd Pointer to ACI command data in ::aci_cmd_t
|
||||
* @param[in] bool
|
||||
*
|
||||
* @return bool true, if succesful, else returns false
|
||||
*/
|
||||
bool acil_encode_cmd(uint8_t *buffer, aci_cmd_t *p_aci_cmd);
|
||||
|
||||
/** @brief Encode the ACI message for Broadcast command
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_aci_cmd Pointer to ACI command data in ::aci_cmd_params_broadcast_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_broadcast(uint8_t *buffer, aci_cmd_params_broadcast_t * p_aci_cmd_params_broadcast);
|
||||
|
||||
/** @brief Encode the ACI message for Open Adv Pipes
|
||||
*
|
||||
* @param[in,out] buffer Pointer to ACI message buffer
|
||||
* @param[in] p_aci_cmd Pointer to ACI command data in ::aci_cmd_params_open_adv_pipe_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_encode_cmd_open_adv_pipes(uint8_t *buffer, aci_cmd_params_open_adv_pipe_t * p_aci_cmd_params_set_adv_svc_data);
|
||||
|
||||
/** @brief Decode the ACI event command response
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] buffer Pointer to the decoded message in ::aci_evt_params_cmd_rsp_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_decode_evt_command_response(uint8_t *buffer_in, aci_evt_params_cmd_rsp_t *p_evt_params_cmd_rsp);
|
||||
|
||||
/** @brief Decode the ACI event device started
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] p_aci_evt Pointer to the decoded message in ::aci_evt_params_device_started_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_decode_evt_device_started(uint8_t *buffer_in, aci_evt_params_device_started_t *p_evt_params_device_started);
|
||||
|
||||
/** @brief Decode the ACI event pipe status
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] p_aci_evt_params_pipe_status Pointer to the decoded message in ::aci_evt_params_pipe_status_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_decode_evt_pipe_status(uint8_t *buffer_in, aci_evt_params_pipe_status_t *p_aci_evt_params_pipe_status);
|
||||
|
||||
/** @brief Decode the ACI event for disconnected
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] p_aci_evt_params_disconnected Pointer to the decoded message in ::aci_evt_params_disconnected_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_decode_evt_disconnected(uint8_t *buffer_in, aci_evt_params_disconnected_t *p_aci_evt_params_disconnected);
|
||||
|
||||
/** @brief Decode the ACI event for bond status
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] p_aci_evt_params_bond_status Pointer to the decoded message in ::aci_evt_params_bond_status_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_decode_evt_bond_status(uint8_t *buffer_in, aci_evt_params_bond_status_t *p_aci_evt_params_bond_status);
|
||||
|
||||
/** @brief Decode the ACI event for data received
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] p_evt_params_data_received Pointer to the decoded message in ::aci_evt_params_data_received_t
|
||||
*
|
||||
* @return size Received data size
|
||||
*/
|
||||
uint8_t acil_decode_evt_data_received(uint8_t *buffer_in, aci_evt_params_data_received_t *p_evt_params_data_received);
|
||||
|
||||
/** @brief Decode the ACI event data acknowledgement
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] p_evt_params_data_ack Pointer to the decoded message in ::aci_evt_params_data_ack_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_decode_evt_data_ack(uint8_t *buffer_in, aci_evt_params_data_ack_t *p_evt_params_data_ack);
|
||||
|
||||
/** @brief Decode the ACI event for hardware error
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] p_aci_evt_params_hw_error Pointer to the decoded message in ::aci_evt_params_hw_error_t
|
||||
*
|
||||
* @return size Size of debug information
|
||||
*/
|
||||
uint8_t acil_decode_evt_hw_error(uint8_t *buffer_in, aci_evt_params_hw_error_t *p_aci_evt_params_hw_error);
|
||||
|
||||
/** @brief Decode the ACI event data credit
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] p_evt_params_data_credit Pointer to the decoded message in ::aci_evt_params_data_credit_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_decode_evt_credit(uint8_t *buffer_in, aci_evt_params_data_credit_t *p_evt_params_data_credit);
|
||||
|
||||
/** @brief Decode the ACI event for connected
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] p_aci_evt_params_connected Pointer to the decoded message in ::aci_evt_params_connected_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_decode_evt_connected(uint8_t *buffer_in, aci_evt_params_connected_t *p_aci_evt_params_connected);
|
||||
|
||||
/** @brief Decode the ACI event for timing
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] p_evt_params_timing Pointer to the decoded message in ::aci_evt_params_timing_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_decode_evt_timing(uint8_t *buffer_in, aci_evt_params_timing_t *p_evt_params_timing);
|
||||
|
||||
/** @brief Decode the ACI event for pipe error
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] p_evt_params_pipe_error Pointer to the decoded message in ::aci_evt_params_pipe_error_t
|
||||
*
|
||||
*/
|
||||
void acil_decode_evt_pipe_error(uint8_t *buffer_in, aci_evt_params_pipe_error_t *p_evt_params_pipe_error);
|
||||
|
||||
/** @brief Decode the ACI event for key request
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] p_evt_params_key_type Pointer to the decoded message in ::aci_evt_params_key_type_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_decode_evt_key_request(uint8_t *buffer_in, aci_evt_params_key_request_t *p_evt_params_key_request);
|
||||
|
||||
/** @brief Decode the ACI event for echo
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] buffer_out Pointer to the echo message (max size of buffer ::ACI_ECHO_DATA_MAX_LEN)
|
||||
*
|
||||
* @return size Received echo message size
|
||||
*/
|
||||
uint8_t acil_decode_evt_echo(uint8_t *buffer_in, aci_evt_params_echo_t *buffer_out);
|
||||
|
||||
/** @brief Decode the ACI event
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] p_aci_evt Pointer to the decoded message in ::aci_evt_t
|
||||
*
|
||||
* @return bool true, if succesful, else returns false
|
||||
*/
|
||||
bool acil_decode_evt(uint8_t *buffer_in, aci_evt_t *p_aci_evt);
|
||||
|
||||
/** @brief Decode the Display Key Event
|
||||
*
|
||||
* @param[in] buffer_in Pointer to message received
|
||||
* @param[in,out] p_aci_evt Pointer to the decoded message in ::aci_evt_params_display_passkey_t
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void acil_decode_evt_display_passkey(uint8_t *buffer_in, aci_evt_params_display_passkey_t *p_aci_evt_params_display_passkey);
|
||||
|
||||
#endif /* _acilib_IF_H_ */
|
||||
25
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/acilib_types.h
Executable file
25
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/acilib_types.h
Executable file
@@ -0,0 +1,25 @@
|
||||
/* Copyright (c) 2010 Nordic Semiconductor. All Rights Reserved.
|
||||
*
|
||||
* The information contained herein is property of Nordic Semiconductor ASA.
|
||||
* Terms and conditions of usage are described in detail in NORDIC
|
||||
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
|
||||
*
|
||||
* Licensees are granted free, non-transferable use of the information. NO
|
||||
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
|
||||
* the file.
|
||||
*
|
||||
* $LastChangedRevision$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup group_acilib
|
||||
*
|
||||
* @brief Type used in the acilib interfaces
|
||||
*/
|
||||
|
||||
#ifndef _acilib_TYPES_H_
|
||||
#define _acilib_TYPES_H_
|
||||
|
||||
#endif /* _acilib_TYPES_H_ */
|
||||
22
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/ble_system.h
Executable file
22
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/ble_system.h
Executable file
@@ -0,0 +1,22 @@
|
||||
#ifndef BLE_SYSTEM_H_
|
||||
#define BLE_SYSTEM_H
|
||||
|
||||
/*
|
||||
#define HAL_IO_RADIO_CSN SS
|
||||
#define HAL_IO_RADIO_REQN SS
|
||||
#define HAL_IO_RADIO_RDY 3
|
||||
#define HAL_IO_RADIO_SCK SCK
|
||||
#define HAL_IO_RADIO_MOSI MOSI
|
||||
#define HAL_IO_RADIO_MISO MISO
|
||||
#define HAL_IO_RADIO_RESET 9
|
||||
#define HAL_IO_RADIO_ACTIVE 8
|
||||
|
||||
//#define HAL_IO_LED0 2
|
||||
//#define HAL_IO_LED1 6
|
||||
*/
|
||||
|
||||
#define ENABLE_INTERRUPTS() sei()
|
||||
#define DISABLE_INTERRUPTS() cli()
|
||||
#define ARE_INTERRUPTS_ENABLED() ((SREG & 0x80) == 0x80)
|
||||
|
||||
#endif
|
||||
55
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/dtm.h
Executable file
55
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/dtm.h
Executable file
@@ -0,0 +1,55 @@
|
||||
/* Copyright (c) 2010 Nordic Semiconductor. All Rights Reserved.
|
||||
*
|
||||
* The information contained herein is property of Nordic Semiconductor ASA.
|
||||
* Terms and conditions of usage are described in detail in NORDIC
|
||||
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
|
||||
*
|
||||
* Licensees are granted free, non-transferable use of the information. NO
|
||||
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
|
||||
* the file.
|
||||
*
|
||||
* $LastChangedRevision$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup group_acilib
|
||||
*
|
||||
* @brief Internal prototype for acilib module.
|
||||
*/
|
||||
|
||||
#ifndef DTM_H__
|
||||
#define DTM_H__
|
||||
|
||||
/** @brief DTM command codes (upper two bits in the DTM command), use a bitwise OR with the frequency N = 0x00 <20> 0x27: N = (F-2402)/2 Frequency Range 2402 MHz
|
||||
to 2480 MHz*/
|
||||
#define DTM_LE_CMD_RESET 0x00
|
||||
#define DTM_LE_CMD_RECEIVER_TEST 0x40
|
||||
#define DTM_LE_CMD_TRANSMITTER_TEST 0x80
|
||||
#define DTM_LE_CMD_TEST_END 0xC0
|
||||
|
||||
|
||||
/** @brief Defined packet types for DTM */
|
||||
#define DTM_LE_PKT_PRBS9 0x00 /**< Bit pattern PRBS9. */
|
||||
#define DTM_LE_PKT_0X0F 0x01 /**< Bit pattern 11110000 (LSB is the leftmost bit). */
|
||||
#define DTM_LE_PKT_0X55 0x02 /**< Bit pattern 10101010 (LSB is the leftmost bit). */
|
||||
#define DTM_LE_PKT_VENDOR 0x03 /**< Vendor specific. Nordic: continous carrier test */
|
||||
|
||||
/** @brief Defined bit fields for DTM responses. */
|
||||
#define LE_PACKET_REPORTING_EVENT_MSB_BIT 0x80
|
||||
#define LE_TEST_STATUS_EVENT_LSB_BIT 0x01
|
||||
|
||||
/** @brief DTM response types. */
|
||||
#define LE_TEST_STATUS_EVENT 0x00
|
||||
#define LE_TEST_PACKET_REPORT_EVENT 0x80
|
||||
|
||||
/** @brief DTM return values. */
|
||||
#define LE_TEST_STATUS_SUCCESS 0x00
|
||||
#define LE_TEST_STATUS_FAILURE 0x01
|
||||
|
||||
|
||||
|
||||
#endif //DTM_H__
|
||||
|
||||
/** @} */
|
||||
108
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/hal/hal_aci_tl.h
Executable file
108
Projects/libraries/Installed_libs/Adafruit_BLE_UART/utility/hal/hal_aci_tl.h
Executable file
@@ -0,0 +1,108 @@
|
||||
/* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
|
||||
*
|
||||
* The information contained herein is property of Nordic Semiconductor ASA.
|
||||
* Terms and conditions of usage are described in detail in NORDIC
|
||||
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
|
||||
*
|
||||
* Licensees are granted free, non-transferable use of the information. NO
|
||||
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
|
||||
* the file.
|
||||
*
|
||||
* $LastChangedRevision$
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* @brief Interface for hal_aci_tl.
|
||||
*/
|
||||
|
||||
/** @defgroup hal_aci_tl hal_aci_tl
|
||||
@{
|
||||
@ingroup hal
|
||||
|
||||
@brief Module for the ACI Transport Layer interface
|
||||
@details This module is responsible for sending and receiving messages over the ACI interface of the nRF8001 chip.
|
||||
The hal_aci_tl_send_cmd() can be called directly to send ACI commands.
|
||||
|
||||
|
||||
The RDYN line is hooked to an interrupt on the MCU when the level is low.
|
||||
The SPI master clocks in the interrupt context.
|
||||
The ACI Command is taken from the head of the command queue is sent over the SPI
|
||||
and the received ACI event is placed in the tail of the event queue.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef HAL_ACI_TL_H__
|
||||
#define HAL_ACI_TL_H__
|
||||
|
||||
#include "hal_platform.h"
|
||||
|
||||
#ifndef HAL_ACI_MAX_LENGTH
|
||||
#define HAL_ACI_MAX_LENGTH 31
|
||||
#endif //HAL_ACI_MAX_LENGTH
|
||||
|
||||
#define ACI_QUEUE_SIZE 8
|
||||
|
||||
/** Data type for ACI commands and events */
|
||||
typedef struct hal_aci_data_t{
|
||||
uint8_t status_byte;
|
||||
uint8_t buffer[HAL_ACI_MAX_LENGTH+1];
|
||||
} hal_aci_data_t;
|
||||
|
||||
|
||||
/** @brief Message received hook function.
|
||||
* @details A hook function that must be implemented by the client of this module.
|
||||
* The function will be called by this module when a new message has been received from the nRF8001.
|
||||
* @param received_msg Pointer to a structure containing a pointer to the received data.
|
||||
*/
|
||||
extern void hal_aci_tl_msg_rcv_hook(hal_aci_data_t *received_msg);
|
||||
|
||||
/** ACI Transport Layer configures inputs/outputs.
|
||||
*/
|
||||
void hal_aci_tl_io_config(void);
|
||||
|
||||
|
||||
/** ACI Transport Layer initialization.
|
||||
*/
|
||||
void hal_aci_tl_init(void);
|
||||
|
||||
/**@brief Sends an ACI command to the radio.
|
||||
* @details
|
||||
* This function sends an ACI command to the radio. This will memorize the pointer of the message to send and
|
||||
* lower the request line. When the device lowers the ready line, @ref hal_aci_tl_poll_rdy_line() will send the data.
|
||||
* @param aci_buffer Pointer to the message to send.
|
||||
* @return True if the send is started successfully, false if a transaction is already running.
|
||||
*/
|
||||
bool hal_aci_tl_send(hal_aci_data_t *aci_buffer);
|
||||
|
||||
|
||||
/** @brief Check for pending transaction.
|
||||
* @details
|
||||
* Call this function from the main context at regular intervals to check if the nRF8001 RDYN line indicates a pending transaction.
|
||||
* If a transaction is pending, this function will treat it and call the receive hook.
|
||||
*/
|
||||
void hal_aci_tl_poll_rdy_line(void);
|
||||
|
||||
hal_aci_data_t * hal_aci_tl_poll_get(void);
|
||||
|
||||
bool hal_aci_tl_event_get(hal_aci_data_t *p_aci_data);
|
||||
|
||||
/** @brief Flush the ACI command Queue and the ACI Event Queue
|
||||
* @details
|
||||
* Call this function in the main thread
|
||||
*/
|
||||
void m_aci_q_flush(void);
|
||||
|
||||
/** @brief Enable debug printing of all ACI commands sent and ACI events received
|
||||
* @details
|
||||
* when the enable parameter is true. The debug printing is enabled on the Serial.
|
||||
* When the enable parameter is false. The debug printing is disabled on the Serial.
|
||||
* By default the debug printing is disabled.
|
||||
*/
|
||||
void hal_aci_debug_print(bool enable);
|
||||
|
||||
#endif // HAL_ACI_TL_H__
|
||||
/** @} */
|
||||
|
||||
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user