added 218 files
This commit is contained in:
parent
57ae8cd836
commit
2c490e7475
BIN
csci218/Labs/.DS_Store
vendored
Normal file
BIN
csci218/Labs/.DS_Store
vendored
Normal file
Binary file not shown.
9
csci218/Labs/Lab1/test/test.ino
Normal file
9
csci218/Labs/Lab1/test/test.ino
Normal file
@ -0,0 +1,9 @@
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
}
|
||||
BIN
csci218/Labs/Textbook/.DS_Store
vendored
Normal file
BIN
csci218/Labs/Textbook/.DS_Store
vendored
Normal file
Binary file not shown.
208866
csci218/Labs/Textbook/Ultimate_Starter_Kit_for_Arduino_V2.pdf
Normal file
208866
csci218/Labs/Textbook/Ultimate_Starter_Kit_for_Arduino_V2.pdf
Normal file
File diff suppressed because one or more lines are too long
BIN
csci218/Labs/Textbook/uctronics_arduino_kits_v2-main/.DS_Store
vendored
Normal file
BIN
csci218/Labs/Textbook/uctronics_arduino_kits_v2-main/.DS_Store
vendored
Normal file
Binary file not shown.
Binary file not shown.
BIN
csci218/Labs/Textbook/uctronics_arduino_kits_v2-main/Code/.DS_Store
vendored
Normal file
BIN
csci218/Labs/Textbook/uctronics_arduino_kits_v2-main/Code/.DS_Store
vendored
Normal file
Binary file not shown.
@ -0,0 +1,23 @@
|
||||
/***********************************************************
|
||||
File name: Blink.ino
|
||||
Description: Turns on an LED on for one second.then off for
|
||||
one second,repeatedly.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
void setup()
|
||||
{
|
||||
//initialize digital pin LED_BUILTIN as an output .
|
||||
pinMode (LED_BUILTIN,OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// put your main code here, to run repeatedly:
|
||||
digitalWrite (LED_BUILTIN,HIGH); //turn the LED on
|
||||
delay (1000); //wait for a second
|
||||
digitalWrite (LED_BUILTIN,LOW); //turn the LED off
|
||||
delay (1000); //wait for a second
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
|
||||
// CONNECTIONS:
|
||||
// DS1302 CLK/SCLK --> 5
|
||||
// DS1302 DAT/IO --> 4
|
||||
// DS1302 RST/CE --> 2
|
||||
// DS1302 VCC --> 3.3v - 5v
|
||||
// DS1302 GND --> GND
|
||||
|
||||
#include <ThreeWire.h>
|
||||
#include <RtcDS1302.h>
|
||||
|
||||
ThreeWire myWire(4,5,2); // IO, SCLK, CE
|
||||
RtcDS1302<ThreeWire> Rtc(myWire);
|
||||
|
||||
#define countof(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
const char data[] = "what time is it";
|
||||
DateTime dt;
|
||||
uint8_t value=0;
|
||||
|
||||
void setup ()
|
||||
{
|
||||
Serial.begin(57600);
|
||||
Rtc.Begin();
|
||||
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
|
||||
Rtc.setDateTime(2017, 6, 13, 16, 29, 3,compiled);
|
||||
}
|
||||
|
||||
void loop ()
|
||||
{
|
||||
char buffer[150]={0};
|
||||
dt = Rtc.DataTime();
|
||||
Serial.print("Long number format: ");
|
||||
Rtc.dateFormat("d-m-Y H:i:s", dt,buffer);
|
||||
Serial.println(buffer);
|
||||
Serial.print("Long format with month name: ");
|
||||
Rtc.dateFormat("d F Y H:i:s", dt,buffer);
|
||||
Serial.println(buffer);
|
||||
Serial.print("Short format witch 12h mode: ");
|
||||
Rtc.dateFormat("jS M y, h:ia", dt,buffer);
|
||||
Serial.println(buffer);
|
||||
Serial.print("Today is: ");
|
||||
Rtc.dateFormat("l, z", dt,buffer);
|
||||
Serial.print(buffer);
|
||||
Serial.println(" days of the year.");
|
||||
Serial.print("Actual month has: ");
|
||||
Rtc.dateFormat("t", dt,buffer);
|
||||
Serial.print(buffer);
|
||||
Serial.println(" days.");
|
||||
Serial.print("Unixtime: ");
|
||||
Rtc.dateFormat("U", dt,buffer);
|
||||
Serial.println(buffer);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_10_Controlling_Relay.ino
|
||||
Description:When the relay sucks, the LED will light up; when
|
||||
the relay breaks, the LED will go out.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
const int relayPin = 8; //the base of the transistor attach to
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(relayPin, OUTPUT); //initialize the relayPin as an output
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
digitalWrite(relayPin, HIGH); //drive relay closure conduction
|
||||
delay(2000); //wait for a second
|
||||
|
||||
digitalWrite(relayPin, LOW); //drive the relay is closed off
|
||||
delay(2000); //wait for a second
|
||||
}
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_11_four_digital_seven_segment_display.ino
|
||||
Description: use 74HC595 to control 4-digit 7-segment display
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
//Pin connected to ST_CP of 74HC595
|
||||
int latch=11;
|
||||
//Pin connected to SH_CP of 74HC595
|
||||
int clock=12;
|
||||
//Pin connected to DS of 74HC595
|
||||
int data=8;
|
||||
|
||||
unsigned char table[]=
|
||||
{0xc0,0xf9,0xa4,0xb0,0x99,
|
||||
0x92,0x82,0xf8,0x80,0x90,
|
||||
0x88,0x83,0xc6,0xa1,0x86,
|
||||
0xff};
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(latch,OUTPUT);
|
||||
pinMode(clock,OUTPUT);
|
||||
pinMode(data,OUTPUT);
|
||||
}
|
||||
void Display(unsigned char num)
|
||||
{
|
||||
|
||||
digitalWrite(latch,LOW);
|
||||
shiftOut(data,clock,MSBFIRST,~table[num]);
|
||||
digitalWrite(latch,HIGH);
|
||||
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
Display(1);
|
||||
delay(500);
|
||||
Display(2);
|
||||
delay(500);
|
||||
Display(3);
|
||||
delay(500);
|
||||
Display(4);
|
||||
delay(500);
|
||||
Display(5);
|
||||
delay(500);
|
||||
Display(6);
|
||||
delay(500);
|
||||
Display(7);
|
||||
delay(500);
|
||||
Display(8);
|
||||
delay(500);
|
||||
Display(9);
|
||||
delay(500);
|
||||
Display(10);
|
||||
delay(500);
|
||||
Display(11);
|
||||
delay(500);
|
||||
Display(12);
|
||||
delay(500);
|
||||
Display(13);
|
||||
delay(500);
|
||||
Display(14);
|
||||
delay(500);
|
||||
Display(15);
|
||||
delay(500);
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_12_Controlling_Serve_motor.ino
|
||||
Description: The servo motor are rotated to 15 degrees, 30
|
||||
degrees, 45 degrees, 60 degrees, 75 degrees,
|
||||
90 degrees, 75 degrees, 60 degrees, 45 degrees,
|
||||
30 degrees, 15 degrees, 0 degrees, and then from
|
||||
0 degrees to 180 degrees and from 180 degrees to
|
||||
0 degrees.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
|
||||
#include <Servo.h>
|
||||
Servo myservo;//create servo object to control a servo
|
||||
|
||||
void setup()
|
||||
{
|
||||
myservo.attach(9);//attachs the servo on pin 9 to servo object
|
||||
myservo.write(0);//back to 0 degrees
|
||||
delay(1000);//wait for a second
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
myservo.write(15);//goes to 15 degrees
|
||||
delay(1000);//wait for a second
|
||||
|
||||
myservo.write(30);//goes to 30 degrees
|
||||
delay(1000);//wait for a second.33
|
||||
|
||||
myservo.write(45);//goes to 45 degrees
|
||||
delay(1000);//wait for a second.33
|
||||
|
||||
myservo.write(60);//goes to 60 degrees
|
||||
delay(1000);//wait for a second.33
|
||||
|
||||
myservo.write(75);//goes to 75 degrees
|
||||
delay(1000);//wait for a second.33
|
||||
|
||||
myservo.write(90);//goes to 90 degrees
|
||||
delay(1000);//wait for a second
|
||||
|
||||
myservo.write(75);//back to 75 degrees
|
||||
delay(1000);//wait for a second.33
|
||||
|
||||
myservo.write(60);//back to 60 degrees
|
||||
delay(1000);//wait for a second.33
|
||||
|
||||
myservo.write(45);//back to 45 degrees
|
||||
delay(1000);//wait for a second.33
|
||||
|
||||
myservo.write(30);//back to 30 degrees
|
||||
delay(1000);//wait for a second.33
|
||||
|
||||
myservo.write(15);//back to 15 degrees
|
||||
delay(1000);//wait for a second
|
||||
|
||||
myservo.write(0);//back to 0 degrees
|
||||
delay(1000);//wait for a second
|
||||
for(int num=0;num<=180;num++)
|
||||
{
|
||||
myservo.write(num);//back to 'num' degrees(0 to 180)
|
||||
delay(10);//control servo speed
|
||||
}
|
||||
for(int num=180;num>=0;num--)
|
||||
{
|
||||
myservo.write(num);//back to 'num' degrees(180 to 0)
|
||||
delay(10);//control servo speed
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_13_Controlling_DC_motor.ino
|
||||
Description: drive the motor using
|
||||
the L9110 chip
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
#define DIRA 4
|
||||
#define DIRB 3
|
||||
|
||||
int i;
|
||||
|
||||
void setup()
|
||||
{
|
||||
//---set pin direction
|
||||
pinMode(DIRA,OUTPUT);
|
||||
pinMode(DIRB,OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
//---back and forth example
|
||||
digitalWrite(DIRA,HIGH); //one way
|
||||
digitalWrite(DIRB,LOW);
|
||||
delay(1000);
|
||||
digitalWrite(DIRA,LOW); //reverse
|
||||
digitalWrite(DIRB,HIGH);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
@ -0,0 +1,95 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_14_Controlling_Stepper_Motor.ino
|
||||
Description: You can observe the stepper motor is fast and
|
||||
forward in a circle, next the stepper motor is
|
||||
slow and reverse in a circle.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
int Pin0 = 11;//definition digital 11 pins as pin to control the IN1 (ULN24L01)
|
||||
int Pin1 = 10;//definition digital 10 pins as pin to control the IN2 (ULN24L01)
|
||||
int Pin2 = 9;//definition digital 9 pins as pin to control the IN3 (ULN24L01)
|
||||
int Pin3 = 8;//definition digital 8 pins as pin to control the IN4 (ULN24L01)
|
||||
|
||||
int _step = 512;
|
||||
int _speed = 1;
|
||||
void setup()
|
||||
{
|
||||
pinMode(Pin0, OUTPUT);//Set digital 8 port mode, the OUTPUT for the output
|
||||
pinMode(Pin1, OUTPUT);//Set digital 9 port mode, the OUTPUT for the output
|
||||
pinMode(Pin2, OUTPUT);//Set digital 10 port mode, the OUTPUT for the output
|
||||
pinMode(Pin3, OUTPUT);//Set digital 11 port mode, the OUTPUT for the output
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Speed(15);//Stepper motor speed = 15 fast (note:speed from 1 to 15)
|
||||
Step(512);//Stepper motor forward 512 steps ---- 360 angle
|
||||
delay(2000);// delay 2S
|
||||
Speed(1); //Stepper motor speed = 1 slow (note:speed from 1 to 15)
|
||||
Step(-512);//Stepper motor backward 512 steps ---- 360 angle
|
||||
delay(2000);//delay 2S
|
||||
}
|
||||
void Speed(int stepperspeed)//set Stepper speed
|
||||
{
|
||||
_speed = 15 - stepperspeed;
|
||||
if( _speed<1){
|
||||
_speed = 1;
|
||||
}
|
||||
if( _speed>15){
|
||||
_speed = 15;
|
||||
}
|
||||
}
|
||||
void Step(int _step)//Stepper motor rotation
|
||||
{
|
||||
if(_step>=0){ // Stepper motor forward
|
||||
for(int i=0;i<_step;i++){
|
||||
setStep(1, 0, 0, 1);
|
||||
delay(_speed);
|
||||
setStep(1, 0, 0, 0);
|
||||
delay(_speed);
|
||||
setStep(1, 1, 0, 0);
|
||||
delay(_speed);
|
||||
setStep(0, 1, 0, 0);
|
||||
delay(_speed);
|
||||
setStep(0, 1, 1, 0);
|
||||
delay(_speed);
|
||||
setStep(0, 0, 1, 0);
|
||||
delay(_speed);
|
||||
setStep(0, 0, 1, 1);
|
||||
delay(_speed);
|
||||
setStep(0, 0, 0, 1);
|
||||
delay(_speed);
|
||||
}
|
||||
}else{ // Stepper motor backward
|
||||
for(int i=_step;i<0;i++){
|
||||
setStep(0, 0, 0, 1);
|
||||
delay(_speed);
|
||||
setStep(0, 0, 1, 1);
|
||||
delay(_speed);
|
||||
setStep(0, 0, 1, 0);
|
||||
delay(_speed);
|
||||
setStep(0, 1, 1, 0);
|
||||
delay(_speed);
|
||||
setStep(0, 1, 0, 0);
|
||||
delay(_speed);
|
||||
setStep(1, 1, 0, 0);
|
||||
delay(_speed);
|
||||
setStep(1, 0, 0, 0);
|
||||
delay(_speed);
|
||||
setStep(1, 0, 0, 1);
|
||||
delay(_speed);
|
||||
}
|
||||
}
|
||||
}
|
||||
void setStep(int a, int b, int c, int d)
|
||||
{
|
||||
digitalWrite(Pin0, a);
|
||||
digitalWrite(Pin1, b);
|
||||
digitalWrite(Pin2, c);
|
||||
digitalWrite(Pin3, d);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_15_Intrusion_Detection_based_on_the_PIR.ino
|
||||
Description: The LED will be turned on when the motion has been detected.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/01/16
|
||||
***********************************************************/
|
||||
|
||||
int ledpin=11; //Set the digital 11 to LED
|
||||
int PIRpin=5; //Set the digital 5 to PIR
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
pinMode( ledpin,OUTPUT); //initialize the led pin as output
|
||||
pinMode( PIRpin,INPUT); //initialize the PIR pin as input
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// put your main code here, to run repeatedly:
|
||||
if(digitalRead(PIRpin)==LOW)
|
||||
{
|
||||
digitalWrite(ledpin,LOW);
|
||||
}else
|
||||
{
|
||||
digitalWrite(ledpin,HIGH);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_16_LCD1602_display.ino
|
||||
Description: use push buttons with digital inputs to turn
|
||||
an LED on and off
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
// 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);
|
||||
/*
|
||||
* LCD RS pin to digital pin 7
|
||||
* LCD Enable pin to digital pin 8
|
||||
* LCD D4 pin to digital pin 9
|
||||
* LCD D5 pin to digital pin 10
|
||||
* LCD D6 pin to digital pin 11
|
||||
* LCD D7 pin to digital pin 12
|
||||
* LCD R/W pin to ground
|
||||
* LCD VSS pin to ground
|
||||
* LCD VCC pin to 5V
|
||||
*/
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("Hello,UCTRONICS!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// set the cursor to column 0, line 1
|
||||
// (note: line 1 is the second row, since counting begins with 0):
|
||||
lcd.setCursor(0, 1);
|
||||
// print the number of seconds since reset:
|
||||
lcd.print(millis() / 1000);
|
||||
}
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_17_Thermometer.ino
|
||||
Description: The temperature was measured using a thermometer
|
||||
and displayed with LCD1602.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
#include <LiquidCrystal.h>
|
||||
int tempPin = A0;
|
||||
// BS E D4 D5 D6 D7
|
||||
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
|
||||
void setup()
|
||||
{
|
||||
lcd.begin(16, 2);
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
int tempReading = analogRead(tempPin);
|
||||
// This is OK
|
||||
double tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
|
||||
tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK ); // Temp Kelvin
|
||||
float tempC = tempK - 273.15; // Convert Kelvin to Celcius
|
||||
float tempF = (tempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
|
||||
/* replaced
|
||||
float tempVolts = tempReading * 5.0 / 1024.0;
|
||||
float tempC = (tempVolts - 0.5) * 10.0;
|
||||
float tempF = tempC * 9.0 / 5.0 + 32.0;
|
||||
*/
|
||||
// Display Temperature in C
|
||||
lcd.setCursor(0, 0);
|
||||
//lcd.print("Temp C ");
|
||||
// Display Temperature in F
|
||||
lcd.print("Temp F ");
|
||||
lcd.setCursor(6, 0);
|
||||
// Display Temperature in C
|
||||
//lcd.print(tempC);
|
||||
// Display Temperature in F
|
||||
lcd.print(tempF);
|
||||
delay(500);
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
/***********************************************************
|
||||
File name: 18_DHT11.ino
|
||||
Description: you can see the temperature and humidity data
|
||||
displayed on the LCD1602.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/01/16
|
||||
***********************************************************/
|
||||
#include <dht11.h>
|
||||
#include <LiquidCrystal.h>
|
||||
dht11 DHT11;
|
||||
int DHT11PIN = A0;
|
||||
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //Define the connection LCD pin
|
||||
/*
|
||||
* LCD RS pin to digital pin 7
|
||||
* LCD Enable pin to digital pin 8
|
||||
* LCD D4 pin to digital pin 9
|
||||
* LCD D5 pin to digital pin 10
|
||||
* LCD D6 pin to digital pin 11
|
||||
* LCD D7 pin to digital pin 12
|
||||
* LCD R/W pin to ground
|
||||
* LCD VSS pin to ground
|
||||
* LCD VCC pin to 5V
|
||||
*/
|
||||
void setup()
|
||||
{
|
||||
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
|
||||
lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner
|
||||
delay(1000); //Delay 1000ms
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int chk = DHT11.read(DHT11PIN);
|
||||
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
|
||||
lcd.print("Humidity:");// Print a message of "Humidity: "to the LCD.
|
||||
lcd.print((float)DHT11.humidity, 2);// Print a message of "Humidity: "to the LCD.
|
||||
lcd.print(" % "); // Print the unit of the centigrade temperature to the LCD.
|
||||
|
||||
lcd.setCursor(0, 1); // set the cursor to column 0, line 1
|
||||
lcd.print("Temp: ");// Print a message of "Temp: "to the LCD.
|
||||
lcd.print((float)DHT11.temperature, 2);// Print a centigrade temperature to the LCD.
|
||||
lcd.print(" C "); // Print the unit of the centigrade temperature to the LCD.
|
||||
delay(1000);
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_19_Joy_stick.ino
|
||||
Description: you can see the joy stick information on the 1602.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
#include <LiquidCrystal.h>
|
||||
/*
|
||||
* LCD RS pin to digital pin 7
|
||||
* LCD Enable pin to digital pin 8
|
||||
* LCD D4 pin to digital pin 9
|
||||
* LCD D5 pin to digital pin 10
|
||||
* LCD D6 pin to digital pin 11
|
||||
* LCD D7 pin to digital pin 12
|
||||
* LCD R/W pin to ground
|
||||
* LCD VSS pin to ground
|
||||
* LCD VCC pin to 5V
|
||||
*/
|
||||
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
|
||||
int JoyStick_X = A1; //PS2 joystick X-axis is defined, ANALOG IN of Pin0
|
||||
int JoyStick_Y = A0; //PS2 joystick Y axis is defined, ANALOG IN of Pin1
|
||||
int JoyStick_Z = 2; //Defined PS2 joystick Z axis,
|
||||
void setup(void)
|
||||
{
|
||||
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
|
||||
lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner
|
||||
pinMode(JoyStick_Z, INPUT_PULLUP); //Z axis is defined as an input PS2
|
||||
}
|
||||
void loop(void)
|
||||
{
|
||||
int x,y,z;
|
||||
x=analogRead(JoyStick_X);
|
||||
y=analogRead(JoyStick_Y);
|
||||
z=digitalRead(JoyStick_Z);
|
||||
|
||||
|
||||
// lcd.setCursor(0, 0); // set the cursor to column 0, line 0
|
||||
// lcd.print("uctronics joy stick");// Print a message of "Temp: "to the LCD.
|
||||
|
||||
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
|
||||
lcd.print("X:");// Print a message of "Temp: "to the LCD.
|
||||
lcd.print(x);// Print a centigrade temperature to the LCD.
|
||||
lcd.print(" ");// Print a message of "Temp: "to the LCD
|
||||
lcd.setCursor(6, 0); // set the cursor to column 0, line 0
|
||||
lcd.print("Y:"); // Print the unit of the centigrade temperature to the LCD.
|
||||
lcd.print(y);// Print a centigrade temperature to the LCD
|
||||
lcd.print(" ");// Print a message of "Temp: "to the LCD
|
||||
lcd.setCursor(13, 0 ); // set the cursor to column 0, line 0
|
||||
lcd.print("Z:"); // Print the unit of the centigrade temperature to the LCD.
|
||||
lcd.print(z);// Print a centigrade temperature to the LCD
|
||||
delay(500);
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_1_Breathe_light.ino
|
||||
Description: PWM control the LED gradually from dark to
|
||||
brighter, then from brighter to dark
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
int ledpin=11; //definition digital 11 pins as pin to control the LED
|
||||
|
||||
void setup ()
|
||||
{
|
||||
pinMode(ledpin,OUTPUT); //Set digital 11 port mode, the OUTPUT for the output
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int a=0; a<=255;a++) //Loop, PWM control of LED brightness increase
|
||||
{
|
||||
analogWrite(ledpin,a); //PWM output value a (0~255)
|
||||
delay(15); //The duration of the current brightness level. 15ms
|
||||
}
|
||||
for (int a=255; a>=0;a--) //Loop, PWM control of LED brightness Reduced
|
||||
{
|
||||
analogWrite(ledpin,a); //PWM output value a (255~0)
|
||||
delay(15); //The duration of the current brightness level. 15ms
|
||||
}
|
||||
delay(100); //100ms delay
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_20_Ultrasonic_distance_sensor.ino
|
||||
Description: When you move the ultrasonic distance sensor,
|
||||
you will find LCD1602 display distance.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
#include <LiquidCrystal.h>
|
||||
const int echoPin = 5; // pin connected to Echo Pin in the ultrasonic distance sensor
|
||||
const int trigPin = 6; // pin connected to trig Pin in the ultrasonic distance sensor
|
||||
|
||||
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
|
||||
/*
|
||||
* LCD RS pin to digital pin 7
|
||||
* LCD Enable pin to digital pin 8
|
||||
* LCD D4 pin to digital pin 9
|
||||
* LCD D5 pin to digital pin 10
|
||||
* LCD D6 pin to digital pin 11
|
||||
* LCD D7 pin to digital pin 12
|
||||
* LCD R/W pin to ground
|
||||
* LCD VSS pin to ground
|
||||
* LCD VCC pin to 5V
|
||||
*/
|
||||
void setup()
|
||||
{
|
||||
pinMode(echoPin, INPUT); //Set the connection pin output mode Echo pin
|
||||
pinMode(trigPin, OUTPUT);//Set the connection pin output mode trog pin
|
||||
lcd.begin(16, 2); //set up the LCD's number of columns and rows:
|
||||
lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner
|
||||
delay(1000); //delay 1000ms
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int cm = ping(echoPin) ;
|
||||
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
|
||||
lcd.print("distance: "); // Print a message of "Temp: "to the LCD.
|
||||
lcd.print(cm); // Print a centigrade temperature to the LCD.
|
||||
lcd.print(" cm "); // Print the unit of the centigrade temperature to the LCD.
|
||||
delay(500);
|
||||
}
|
||||
|
||||
int ping(int echoPin)
|
||||
{
|
||||
// establish variables for duration of the ping,
|
||||
// and the distance result in inches and centimeters:
|
||||
long duration, cm;
|
||||
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
|
||||
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
|
||||
pinMode(trigPin, OUTPUT);
|
||||
digitalWrite(trigPin, LOW);
|
||||
delayMicroseconds(2);
|
||||
digitalWrite(trigPin, HIGH);
|
||||
delayMicroseconds(5);
|
||||
digitalWrite(trigPin, LOW);
|
||||
|
||||
pinMode(echoPin, INPUT);
|
||||
duration = pulseIn(echoPin, HIGH);
|
||||
|
||||
// convert the time into a distance
|
||||
cm = microsecondsToCentimeters(duration);
|
||||
return cm ;
|
||||
}
|
||||
|
||||
long microsecondsToCentimeters(long microseconds)
|
||||
{
|
||||
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
|
||||
// The ping travels out and back, so to find the distance of the
|
||||
// object we take half of the distance travelled.
|
||||
return microseconds / 29 / 2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_21_IR_receiver_remote.ino
|
||||
Description: use an IR receiver to receive the remote
|
||||
controller signal.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
#include "NECIRrcv.h"
|
||||
NECIRrcv IR_1(11);
|
||||
int i=0;
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
IR_1.begin();
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
while(IR_1.available())
|
||||
{
|
||||
// Serial.println(IR_1.read(),HEX);
|
||||
|
||||
switch(IR_1.read())
|
||||
{
|
||||
case 0xFF16E9: Serial.println("0"); break;
|
||||
case 0xFF0CF3: Serial.println("1"); break;
|
||||
case 0xFF18E7: Serial.println("2"); break;
|
||||
case 0xFF5EA1: Serial.println("3"); break;
|
||||
case 0xFF08F7: Serial.println("4"); break;
|
||||
case 0xFF1CE3: Serial.println("5"); break;
|
||||
case 0xFF5AA5: Serial.println("6"); break;
|
||||
case 0xFF42BD: Serial.println("7"); break;
|
||||
case 0xFF52AD: Serial.println("8"); break;
|
||||
case 0xFF4AB5: Serial.println("9"); break;
|
||||
case 0xFFFFFFFF: Serial.println(" REPEAT");break;
|
||||
|
||||
default: Serial.println(" other button ");
|
||||
|
||||
}// End Case
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_22_LED_bar_graph_display.ino
|
||||
Description: Control LED bar graph shows the change in
|
||||
resistance value.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
int pin1 = 1;
|
||||
int pin2 = 2;
|
||||
int pin3 = 3;
|
||||
int pin4 = 4;
|
||||
int pin5 = 5;
|
||||
int pin6 = 6;
|
||||
int pin7 = 7;
|
||||
int pin8 = 8;
|
||||
int pin9 = 9;
|
||||
int pin10 = 10; //definition digital 10 pins as pin to control the LED
|
||||
|
||||
int potentiometerPin = A0; // potentiometer connected to analog pin A0
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(pin1,OUTPUT); //Set the digital 1 port mode, OUTPUT: Output mode
|
||||
pinMode(pin2,OUTPUT); //Set the digital 2 port mode, OUTPUT: Output mode
|
||||
pinMode(pin3,OUTPUT); //Set the digital 3 port mode, OUTPUT: Output mode
|
||||
pinMode(pin4,OUTPUT); //Set the digital 4 port mode, OUTPUT: Output mode
|
||||
pinMode(pin5,OUTPUT); //Set the digital 5 port mode, OUTPUT: Output mode
|
||||
pinMode(pin6,OUTPUT); //Set the digital 6 port mode, OUTPUT: Output mode
|
||||
pinMode(pin7,OUTPUT); //Set the digital 7 port mode, OUTPUT: Output mode
|
||||
pinMode(pin8,OUTPUT); //Set the digital 8 port mode, OUTPUT: Output mode
|
||||
pinMode(pin9,OUTPUT); //Set the digital 9 port mode, OUTPUT: Output mode
|
||||
pinMode(pin10,OUTPUT); //Set the digital 10 port mode, OUTPUT: Output mode
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
float a = analogRead(potentiometerPin);//Read the voltage photoresistance
|
||||
a = map(a,0,1023,0,11); //Photoresistor voltage value converted from 0-1023 to 0-11
|
||||
for(int i=1;i<=a;i++){
|
||||
digitalWrite(i,HIGH); //HIGH is set to about 5V PIN8
|
||||
}
|
||||
for(int j=10;j>a;j--){
|
||||
digitalWrite(j,LOW); //HIGH is set to about 5V PIN8
|
||||
}
|
||||
delay(50); //delay 50ms
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_23_4x4_matrix_keyboard.ino
|
||||
Description: when you click the button on the 4x4 matrix
|
||||
keyboard,you can see the serial monitoring
|
||||
of water level data.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
#include <Keypad.h>
|
||||
|
||||
const byte ROWS = 4; //four rows
|
||||
const byte COLS = 4; //four columns
|
||||
//define the cymbols on the buttons of the keypads
|
||||
char hexaKeys[ROWS][COLS] =
|
||||
{
|
||||
{'1','2','3','A'},
|
||||
{'4','5','6','B'},
|
||||
{'7','8','9','C'},
|
||||
{'*','0','#','D'}
|
||||
};
|
||||
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
|
||||
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
|
||||
|
||||
//initialize an instance of class NewKeypad
|
||||
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);//Open serial
|
||||
}
|
||||
|
||||
void loop(){
|
||||
char customKey = customKeypad.getKey();//Read Key data
|
||||
if (customKey){
|
||||
Serial.println(customKey); //send the key data by serial port (UART)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
|
||||
// CONNECTIONS:
|
||||
// DS1302 CLK/SCLK --> 5
|
||||
// DS1302 DAT/IO --> 4
|
||||
// DS1302 RST/CE --> 2
|
||||
// DS1302 VCC --> 3.3v - 5v
|
||||
// DS1302 GND --> GND
|
||||
|
||||
#include <ThreeWire.h>
|
||||
#include <RtcDS1302.h>
|
||||
|
||||
ThreeWire myWire(4,5,2); // IO, SCLK, CE
|
||||
RtcDS1302<ThreeWire> Rtc(myWire);
|
||||
|
||||
#define countof(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
const char data[] = "what time is it";
|
||||
DateTime dt;
|
||||
uint8_t value=0;
|
||||
|
||||
void setup ()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Rtc.Begin();
|
||||
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
|
||||
Rtc.setDateTime(2017, 6, 13, 16, 29, 3,compiled);
|
||||
}
|
||||
|
||||
void loop ()
|
||||
{
|
||||
char buffer[150]={0};
|
||||
dt = Rtc.DataTime();
|
||||
Serial.print("Long number format: ");
|
||||
Rtc.dateFormat("d-m-Y H:i:s", dt,buffer);
|
||||
Serial.println(buffer);
|
||||
Serial.print("Long format with month name: ");
|
||||
Rtc.dateFormat("d F Y H:i:s", dt,buffer);
|
||||
Serial.println(buffer);
|
||||
Serial.print("Short format witch 12h mode: ");
|
||||
Rtc.dateFormat("jS M y, h:ia", dt,buffer);
|
||||
Serial.println(buffer);
|
||||
Serial.print("Today is: ");
|
||||
Rtc.dateFormat("l, z", dt,buffer);
|
||||
Serial.print(buffer);
|
||||
Serial.println(" days of the year.");
|
||||
Serial.print("Actual month has: ");
|
||||
Rtc.dateFormat("t", dt,buffer);
|
||||
Serial.print(buffer);
|
||||
Serial.println(" days.");
|
||||
Serial.print("Unixtime: ");
|
||||
Rtc.dateFormat("U", dt,buffer);
|
||||
Serial.println(buffer);
|
||||
delay(1000);
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_25_water_level_detection_sensor_module.ino
|
||||
Description: when you open the serial monitor, you can see
|
||||
the serial port prints data of water level.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
int adc_id = A0;
|
||||
int HistoryValue = 0;
|
||||
char printBuffer[128];
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
long temp_max,temp_min, temp_value,temp;
|
||||
long value = 0;
|
||||
temp_max = analogRead(adc_id); // get adc value
|
||||
temp_min = temp_max;
|
||||
temp_value= temp_max;
|
||||
|
||||
for(int i = 0; i < 201; i ++ ){
|
||||
temp = analogRead(adc_id);
|
||||
if(temp_max<temp) temp_max = temp;
|
||||
if(temp_min>temp) temp_min = temp;
|
||||
temp_value += temp;
|
||||
}
|
||||
value =(temp_value-temp_max-temp_min)/200;
|
||||
if(HistoryValue!=value)
|
||||
{
|
||||
sprintf(printBuffer,"ADC%d level is %d\n",adc_id, value);
|
||||
Serial.print(printBuffer);
|
||||
HistoryValue = value;
|
||||
delay(500);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_26_Sound_Sensor_Module.ino
|
||||
Description: When you talk to the microphone, the serial
|
||||
port will print out the value of volume,and the
|
||||
LED will be lit when you speak.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
int sensorPin = A0; // select the input pin for the potentiometer
|
||||
int ledPin = 13; // select the pin for the LED
|
||||
int sensorValue = 0; // variable to store the value coming from the sensor
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(ledPin,OUTPUT);
|
||||
Serial.begin(9600);
|
||||
}
|
||||
void loop(){
|
||||
sensorValue = analogRead(sensorPin);
|
||||
digitalWrite(ledPin, HIGH);
|
||||
delay(sensorValue);
|
||||
digitalWrite(ledPin, LOW);
|
||||
delay(sensorValue);
|
||||
Serial.println(sensorValue, DEC);
|
||||
}
|
||||
|
||||
@ -0,0 +1,150 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_27_max7219_led_dot_matrix_module.ino
|
||||
Description: control a 8x8 dot-matrix display the characters
|
||||
for the word "UCTRONICS" one after the other
|
||||
on the matrix
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
#include "LedControl.h"
|
||||
/*
|
||||
***** These pin numbers will probably not work with your hardware *****
|
||||
pin 12 is connected to the DataIn
|
||||
pin 11 is connected to LOAD(CS)
|
||||
pin 10 is connected to the CLK
|
||||
We have only a single MAX72XX.
|
||||
*/
|
||||
LedControl lc=LedControl(12,10,11,1);
|
||||
|
||||
/* we always wait a bit between updates of the display */
|
||||
unsigned long delaytime1=1000;
|
||||
unsigned long delaytime2=50;
|
||||
void setup()
|
||||
{
|
||||
/*
|
||||
The MAX72XX is in power-saving mode on startup,
|
||||
we have to do a wakeup call
|
||||
*/
|
||||
lc.shutdown(0,false);
|
||||
/* Set the brightness to a medium values */
|
||||
lc.setIntensity(0,8);
|
||||
/* and clear the display */
|
||||
lc.clearDisplay(0);
|
||||
}
|
||||
/*
|
||||
This method will display the characters for the
|
||||
word "UCTRONICS" one after the other on the matrix.
|
||||
(you need at least 5x7 leds to see the whole chars)
|
||||
*/
|
||||
void writeArduinoOnMatrix()
|
||||
{
|
||||
/* here is the data for the characters */
|
||||
byte u[7]={B00010001,B00010001,B00010001,B00010001,B00010001,B00010001,B00001110};
|
||||
byte c[7]={B00001111,B00010000,B00010000,B00010000,B00010000,B00010000,B00001111};
|
||||
byte t[7]={B00011111,B00000100,B00000100,B00000100,B00000100,B00000100,B00000100};
|
||||
byte r[7]={B00011100,B00010010,B00010010,B00011100,B00011000,B00010100,B00010010};
|
||||
byte o[7]={B00001110,B00010001,B00010001,B00010001,B00010001,B00010001,B00001110};
|
||||
byte n[7]={B00000000,B00010001,B00011001,B00010101,B00010011,B00010001,B00000000};
|
||||
byte i[7]={B00011111,B00000100,B00000100,B00000100,B00000100,B00000100,B00011111};
|
||||
byte s[7]={B00001111,B00001000,B00001000,B00001111,B00000001,B00000001,B00001111};
|
||||
|
||||
/* now display them one by one with a small delay */
|
||||
lc.setRow(0,0,u[0]);
|
||||
lc.setRow(0,1,u[1]);
|
||||
lc.setRow(0,2,u[2]);
|
||||
lc.setRow(0,3,u[3]);
|
||||
lc.setRow(0,4,u[4]);
|
||||
lc.setRow(0,5,u[5]);
|
||||
lc.setRow(0,6,u[6]);
|
||||
delay(delaytime1);
|
||||
lc.setRow(0,0,c[0]);
|
||||
lc.setRow(0,1,c[1]);
|
||||
lc.setRow(0,2,c[2]);
|
||||
lc.setRow(0,3,c[3]);
|
||||
lc.setRow(0,4,c[4]);
|
||||
lc.setRow(0,5,c[5]);
|
||||
lc.setRow(0,6,c[6]);
|
||||
delay(delaytime1);
|
||||
lc.setRow(0,0,t[0]);
|
||||
lc.setRow(0,1,t[1]);
|
||||
lc.setRow(0,2,t[2]);
|
||||
lc.setRow(0,3,t[3]);
|
||||
lc.setRow(0,4,t[4]);
|
||||
lc.setRow(0,5,t[5]);
|
||||
lc.setRow(0,6,t[6]);
|
||||
delay(delaytime1);
|
||||
lc.setRow(0,0,r[0]);
|
||||
lc.setRow(0,1,r[1]);
|
||||
lc.setRow(0,2,r[2]);
|
||||
lc.setRow(0,3,r[3]);
|
||||
lc.setRow(0,4,r[4]);
|
||||
lc.setRow(0,5,r[5]);
|
||||
lc.setRow(0,6,r[6]);
|
||||
delay(delaytime1);
|
||||
lc.setRow(0,0,o[0]);
|
||||
lc.setRow(0,1,o[1]);
|
||||
lc.setRow(0,2,o[2]);
|
||||
lc.setRow(0,3,o[3]);
|
||||
lc.setRow(0,4,o[4]);
|
||||
lc.setRow(0,5,o[5]);
|
||||
lc.setRow(0,6,o[6]);
|
||||
delay(delaytime1);
|
||||
lc.setRow(0,0,n[0]);
|
||||
lc.setRow(0,1,n[1]);
|
||||
lc.setRow(0,2,n[2]);
|
||||
lc.setRow(0,3,n[3]);
|
||||
lc.setRow(0,4,n[4]);
|
||||
lc.setRow(0,5,n[5]);
|
||||
lc.setRow(0,6,n[6]);
|
||||
delay(delaytime1);
|
||||
lc.setRow(0,0,i[0]);
|
||||
lc.setRow(0,1,i[1]);
|
||||
lc.setRow(0,2,i[2]);
|
||||
lc.setRow(0,3,i[3]);
|
||||
lc.setRow(0,4,i[4]);
|
||||
lc.setRow(0,5,i[5]);
|
||||
lc.setRow(0,6,i[6]);
|
||||
delay(delaytime1);
|
||||
lc.setRow(0,0,c[0]);
|
||||
lc.setRow(0,1,c[1]);
|
||||
lc.setRow(0,2,c[2]);
|
||||
lc.setRow(0,3,c[3]);
|
||||
lc.setRow(0,4,c[4]);
|
||||
lc.setRow(0,5,c[5]);
|
||||
lc.setRow(0,6,c[6]);
|
||||
delay(delaytime1);
|
||||
lc.setRow(0,0,s[0]);
|
||||
lc.setRow(0,1,s[1]);
|
||||
lc.setRow(0,2,s[2]);
|
||||
lc.setRow(0,3,s[3]);
|
||||
lc.setRow(0,4,s[4]);
|
||||
lc.setRow(0,5,s[5]);
|
||||
lc.setRow(0,6,s[6]);
|
||||
delay(delaytime1);
|
||||
lc.setRow(0,0,0);
|
||||
lc.setRow(0,1,0);
|
||||
lc.setRow(0,2,0);
|
||||
lc.setRow(0,3,0);
|
||||
lc.setRow(0,4,0);
|
||||
lc.setRow(0,5,0);
|
||||
lc.setRow(0,6,0);
|
||||
delay(delaytime1);
|
||||
}
|
||||
|
||||
void clearLed ()
|
||||
{
|
||||
for(int row=0;row<8;row++)
|
||||
{
|
||||
for(int col=0;col<8;col++)
|
||||
{
|
||||
lc.setLed(0,row,col,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
writeArduinoOnMatrix();
|
||||
clearLed ();
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_28_Frequency_meter.ino
|
||||
Description: Use Arduino UNO R3 or Mega 2560 gathering issued NE555 square wave.
|
||||
Square wave frequency values were collected via a
|
||||
serial port will be sent to the serial monitor display.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
int pin = 7; //attach to the third pin of NE555
|
||||
|
||||
unsigned long duration; //the variable to store the length of the pulse
|
||||
unsigned long durationhigh;//the variable to store the length of the pulse
|
||||
unsigned long durationlow; //the variable to store the length of the pulse
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(pin, INPUT); //set the pin as an input
|
||||
Serial.begin(9600); // start serial port at 9600 bps:
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
durationhigh = pulseIn(pin, HIGH); //Reads a pulse on pin
|
||||
durationlow = pulseIn(pin, LOW); //Reads a pulse on pin
|
||||
duration = 1000000/(durationhigh + durationlow);
|
||||
Serial.print("Freq: "); //print Freq:
|
||||
Serial.print(duration); //print the length of the pulse on the serial monitor
|
||||
Serial.print("Hz HTime: "); //print Hz HTime:
|
||||
Serial.print(durationhigh); //print the length of the pulse on the serial monitor
|
||||
Serial.print("us LTime: "); //print us LTime:
|
||||
Serial.print(durationlow); //print the length of the pulse on the serial monitor
|
||||
Serial.print("us "); //print us
|
||||
Serial.println(); //print an blank on serial monitor
|
||||
delay(500); //wait for 500 microseconds
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_29_mpu6050_module.ino
|
||||
Description: Use the MPU6050 to display acceleration and
|
||||
angular velocityof X,Y,Z.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
#include<Wire.h>
|
||||
const int MPU_addr=0x68; // I2C address of the MPU-6050
|
||||
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
|
||||
void setup(){
|
||||
Wire.begin();
|
||||
Wire.beginTransmission(MPU_addr);
|
||||
Wire.write(0x6B); // PWR_MGMT_1 register
|
||||
Wire.write(0); // set to zero (wakes up the MPU-6050)
|
||||
Wire.endTransmission(true);
|
||||
Serial.begin(9600);
|
||||
}
|
||||
void loop(){
|
||||
Wire.beginTransmission(MPU_addr);
|
||||
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
|
||||
Wire.endTransmission(false);
|
||||
Wire.requestFrom(MPU_addr,14,true); // request a total of 14 registers
|
||||
AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
|
||||
AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
|
||||
AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
|
||||
Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
|
||||
GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
|
||||
GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
|
||||
GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
|
||||
Serial.print("AcX = "); Serial.print(AcX);
|
||||
Serial.print(" | AcY = "); Serial.print(AcY);
|
||||
Serial.print(" | AcZ = "); Serial.print(AcZ);
|
||||
Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53); //equation for temperature in degrees C from datasheet
|
||||
Serial.print(" | GyX = "); Serial.print(GyX);
|
||||
Serial.print(" | GyY = "); Serial.print(GyY);
|
||||
Serial.print(" | GyZ = "); Serial.println(GyZ);
|
||||
delay(333);
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_2_LED_Flowing_Lights.ino
|
||||
Description: LED turn lighting control
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
//Pin connected to ST_CP of 74HC595
|
||||
int latchPin = 11;
|
||||
//Pin connected to SH_CP of 74HC595
|
||||
int clockPin = 12;
|
||||
////Pin connected to DS of 74HC595
|
||||
int dataPin = 8;
|
||||
|
||||
void setup()
|
||||
{
|
||||
//set pins to output because they are addressed in the main loop
|
||||
pinMode(latchPin, OUTPUT);
|
||||
pinMode(clockPin, OUTPUT);
|
||||
pinMode(dataPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int j=1,dire;
|
||||
while (1) //count up routine
|
||||
{
|
||||
//ground latchPin and hold low for as long as you are transmitting
|
||||
digitalWrite(latchPin, LOW);
|
||||
shiftOut(dataPin, clockPin, LSBFIRST, j); //return the latch pin high to signal chip that it
|
||||
//no longer needs to listen for information
|
||||
digitalWrite(latchPin, HIGH);
|
||||
if (j==1)
|
||||
dire=1;
|
||||
else if (j==128)
|
||||
dire=0;
|
||||
if (dire==1)
|
||||
j=j<<1;
|
||||
else
|
||||
j=j>>1;
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_30_controlling_stepper_motor_with_remote.ino
|
||||
Description: control a stepper motor from a distance using
|
||||
an IR remote control.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
#include "Stepper.h"
|
||||
#include "NECIRrcv.h"
|
||||
NECIRrcv IR_1(12);
|
||||
|
||||
/*----- Variables, Pins -----*/
|
||||
#define STEPS 32 // Number of steps per revolution of Internal shaft
|
||||
int Steps2Take; // 2048 = 1 Revolution
|
||||
|
||||
/*-----( Declare objects )-----*/
|
||||
// Setup of proper sequencing for Motor Driver Pins
|
||||
// In1, In2, In3, In4 in the sequence 1-3-2-4
|
||||
uint32_t Val = 0;
|
||||
Stepper small_stepper(STEPS, 8, 10, 9, 11);
|
||||
void setup()
|
||||
{
|
||||
IR_1.begin();
|
||||
Serial.begin (9600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (IR_1.available()) // have we received an IR signal?
|
||||
|
||||
{
|
||||
Val = IR_1.read();
|
||||
Serial.println(Val,HEX);
|
||||
switch(Val)
|
||||
{
|
||||
|
||||
case 0xFF0CF3: // 1 button pressed
|
||||
small_stepper.setSpeed(500); //Max seems to be 500
|
||||
Steps2Take = 2048; // Rotate CW
|
||||
small_stepper.step(Steps2Take);
|
||||
delay(2000);
|
||||
break;
|
||||
|
||||
case 0xFF18E7: // 2 button pressed
|
||||
small_stepper.setSpeed(500);
|
||||
Steps2Take = -2048; // Rotate CCW
|
||||
small_stepper.step(Steps2Take);
|
||||
delay(2000);
|
||||
break;
|
||||
|
||||
}
|
||||
digitalWrite(8, LOW);
|
||||
digitalWrite(9, LOW);
|
||||
digitalWrite(10, LOW);
|
||||
digitalWrite(11, LOW);
|
||||
}
|
||||
|
||||
|
||||
}/* --end main loop -- */
|
||||
@ -0,0 +1,93 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_31_controlling_stepper_motor_with_rotary_encoder.ino
|
||||
Description: control stepper motors using a rotary encoder.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
#include "Stepper.h"
|
||||
#define STEPS 32 // Number of steps for one revolution of Internal shaft
|
||||
// 2048 steps for one revolution of External shaft
|
||||
|
||||
volatile boolean TurnDetected; // need volatile for Interrupts
|
||||
volatile boolean rotationdirection; // CW or CCW rotation
|
||||
|
||||
const int PinCLK=2; // Generating interrupts using CLK signal
|
||||
const int PinDT=3; // Reading DT signal
|
||||
const int PinSW=4; // Reading Push Button switch
|
||||
|
||||
int RotaryPosition=0; // To store Stepper Motor Position
|
||||
|
||||
int PrevPosition; // Previous Rotary position Value to check accuracy
|
||||
int StepsToTake; // How much to move Stepper
|
||||
|
||||
// Setup of proper sequencing for Motor Driver Pins
|
||||
// In1, In2, In3, In4 in the sequence 1-3-2-4
|
||||
Stepper small_stepper(STEPS, 8, 10, 9, 11);
|
||||
|
||||
// Interrupt routine runs if CLK goes from HIGH to LOW
|
||||
void isr ()
|
||||
{
|
||||
delay(4); // delay for Debouncing
|
||||
if (digitalRead(PinCLK))
|
||||
rotationdirection= digitalRead(PinDT);
|
||||
else
|
||||
rotationdirection= !digitalRead(PinDT);
|
||||
TurnDetected = true;
|
||||
}
|
||||
|
||||
void setup ()
|
||||
{
|
||||
pinMode(PinCLK,INPUT);
|
||||
pinMode(PinDT,INPUT);
|
||||
pinMode(PinSW,INPUT);
|
||||
digitalWrite(PinSW, HIGH); // Pull-Up resistor for switch
|
||||
attachInterrupt (0,isr,FALLING); // interrupt 0 always connected to pin 2 on Arduino UNO
|
||||
}
|
||||
|
||||
void loop ()
|
||||
{
|
||||
small_stepper.setSpeed(700); //Max seems to be 700
|
||||
if (!(digitalRead(PinSW)))
|
||||
{ // check if button is pressed
|
||||
if (RotaryPosition == 0)
|
||||
{ // check if button was already pressed
|
||||
}
|
||||
else
|
||||
{
|
||||
small_stepper.step(-(RotaryPosition*50));
|
||||
RotaryPosition=0; // Reset position to ZERO
|
||||
}
|
||||
}
|
||||
|
||||
// Runs if rotation was detected
|
||||
if (TurnDetected)
|
||||
{
|
||||
PrevPosition = RotaryPosition; // Save previous position in variable
|
||||
if (rotationdirection)
|
||||
{
|
||||
RotaryPosition=RotaryPosition-1;
|
||||
} // decrase Position by 1
|
||||
else
|
||||
{
|
||||
RotaryPosition=RotaryPosition+1;
|
||||
} // increase Position by 1
|
||||
TurnDetected = false; // do NOT repeat IF loop until new rotation detected
|
||||
// Which direction to move Stepper motor
|
||||
if ((PrevPosition + 1) == RotaryPosition)
|
||||
{ // Move motor CW
|
||||
StepsToTake=50;
|
||||
small_stepper.step(StepsToTake);
|
||||
}
|
||||
if ((RotaryPosition + 1) == PrevPosition)
|
||||
{ // Move motor CCW
|
||||
StepsToTake=-50;
|
||||
small_stepper.step(StepsToTake);
|
||||
}
|
||||
}
|
||||
digitalWrite(8, LOW);
|
||||
digitalWrite(9, LOW);
|
||||
digitalWrite(10, LOW);
|
||||
digitalWrite(11, LOW);
|
||||
}
|
||||
@ -0,0 +1,143 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_32_ESP8266.ino
|
||||
Description: Remote control some devices by using the ESP8266
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
|
||||
#define SSID "KK" //type your own SSID name
|
||||
#define PASSWORD "12345687" //type your own WIFI password
|
||||
|
||||
#include "uartWIFI.h"
|
||||
#include <SoftwareSerial.h>
|
||||
WIFI wifi;
|
||||
extern int chlID; //client id(0-4)
|
||||
int Send_Debug_EN = 0,Send_Con_EN=0;
|
||||
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(4,OUTPUT);
|
||||
Serial.begin (9600);
|
||||
wifi.begin();
|
||||
bool b = wifi.Initialize(AP_STA, SSID, PASSWORD);
|
||||
if(!b)
|
||||
{
|
||||
Serial.println("Init error");
|
||||
}
|
||||
delay(1000); //make sure the module can have enough time to get an IP address
|
||||
String ipstring = wifi.showIP();
|
||||
int ip_dress_1=ipstring.indexOf('"');
|
||||
int ip_dress_2=ipstring.indexOf('"',ip_dress_1 + 1);
|
||||
int ip_dress_3=ipstring.indexOf('"',ip_dress_2 + 40);
|
||||
int ip_dress_4=ipstring.indexOf('"',ip_dress_3 + 1);
|
||||
Serial.print("APIP:"); //show the ip address of module
|
||||
Serial.println(ipstring.substring(ip_dress_1,ip_dress_2+1));
|
||||
Serial.print("STAIP:");
|
||||
Serial.println(ipstring.substring(ip_dress_3,ip_dress_4+1));
|
||||
|
||||
delay(1000);
|
||||
wifi.confMux(1);
|
||||
delay(100);
|
||||
if(wifi.confServer(1,8089))
|
||||
Serial.println("Server is set up");
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
char buf[100];
|
||||
int iLen = wifi.ReceiveMessage(buf); // Read the data received by wifi
|
||||
|
||||
|
||||
if(iLen > 0)
|
||||
{
|
||||
//delay (10);
|
||||
//Serial.println (buf);
|
||||
if (buf[5]=='o'&&buf[6]=='n') // CH0 ON
|
||||
{
|
||||
digitalWrite (4,LOW);
|
||||
Serial.println ("CH0 ON");
|
||||
Send_Debug_EN = 1;
|
||||
Response ();
|
||||
delay (100);
|
||||
}
|
||||
if (buf[5]=='o'&&buf[6]=='f'&&buf[7]=='f') // CH0 OFF
|
||||
{
|
||||
digitalWrite (4,HIGH);
|
||||
Serial.println ("CH0 OFF");
|
||||
Send_Debug_EN = 1;
|
||||
Response ();
|
||||
delay (100);
|
||||
}
|
||||
if (buf[5]=='c'&&buf[6]=='o'&&buf[7]=='n') // CH0 OFF
|
||||
{
|
||||
Serial.println ("Connected");
|
||||
Send_Con_EN = 1;
|
||||
Response ();
|
||||
delay (100);
|
||||
}
|
||||
}
|
||||
delay (50);
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
Function of respond to phone's commands
|
||||
***********************************************************/
|
||||
|
||||
void Response ()
|
||||
{
|
||||
_cell.print("AT+CIPSEND=0,126\r\n");
|
||||
unsigned long start;
|
||||
bool found;
|
||||
start = millis();
|
||||
while (millis()-start<250)
|
||||
{
|
||||
if(_cell.find(">")==true )
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(found)
|
||||
{
|
||||
_cell.print("HTTP/1.1 200 OK\r\nDate: Sat, 31 Dec 2005 23:59:59 GMT\r\nContent-Type: text/html;charset=ISO-8859-1\r\nContent-Length: 7\r\n\r\n");
|
||||
if (Send_Debug_EN)
|
||||
{
|
||||
_cell.print("debugen");
|
||||
Send_Debug_EN=0;
|
||||
}
|
||||
if (Send_Con_EN)
|
||||
{
|
||||
_cell.print("connect");
|
||||
Send_Con_EN=0;
|
||||
}
|
||||
|
||||
_cell.print("\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
wifi.closeMux();
|
||||
}
|
||||
String data;
|
||||
start = millis();
|
||||
while (millis()-start<250)
|
||||
{
|
||||
if(_cell.available()>0)
|
||||
{
|
||||
char a =_cell.read();
|
||||
data=data+a;
|
||||
}
|
||||
if (data.indexOf("SEND OK")!=-1)
|
||||
{
|
||||
Serial.println("Send OK");
|
||||
break;
|
||||
}
|
||||
}
|
||||
_cell.print("AT+CIPCLOSE=0\r\n");
|
||||
}
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_24_real_time_clock_module.ino
|
||||
Description: Calibration clock.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
#include <ThreeWire.h>
|
||||
#include <RtcDS1302.h>
|
||||
|
||||
ThreeWire myWire(14,15,16); // IO, SCLK, CE
|
||||
RtcDS1302<ThreeWire> Rtc(myWire);
|
||||
DateTime dt;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Rtc.Begin();
|
||||
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
|
||||
Rtc.setDateTime(2021,4,13,13,49,0,compiled);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
@ -0,0 +1,402 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_33_Build_a_Smart_Home_System.ino
|
||||
Description: Build a simulated smart home system by
|
||||
using the ESP8266 and some other sensor
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
#include <dht11.h>
|
||||
#include <LiquidCrystal.h>
|
||||
#include <Wire.h>
|
||||
#include <ThreeWire.h>
|
||||
#include <RtcDS1302.h>
|
||||
#include "uartWIFI.h"
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#define SSID "KK" //type your own SSID name
|
||||
#define PASSWORD "12345687" //type your own WIFI password
|
||||
|
||||
#define Temp_maxlimit 30 // type your Maximum temperature
|
||||
#define Temp_minlimit 24 // type your Minimum temperature
|
||||
|
||||
|
||||
WIFI wifi;
|
||||
extern int chlID; //client id(0-4)
|
||||
|
||||
ThreeWire myWire(14,15,16); // IO, SCLK, CE
|
||||
RtcDS1302<ThreeWire> Rtc(myWire);
|
||||
DateTime dt;
|
||||
dht11 DHT11;
|
||||
|
||||
const int DHT11PIN = A0;
|
||||
const int IN1 = 3;
|
||||
const int IN2 = 4;
|
||||
const int IN3 = 5;
|
||||
const int IN4 = 6;
|
||||
|
||||
int lcd_off1=0,n=0;
|
||||
int data1,data2;
|
||||
|
||||
int now_temp,now_distance,now_light;
|
||||
bool send_tmp_EN=0,send_hum_EN=0,send_DEBUG_EN=0,send_con_EN=0;
|
||||
int timer1_counter;
|
||||
|
||||
bool warning_1,warning_2,MODE_0=0;
|
||||
|
||||
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(IN1, OUTPUT);
|
||||
pinMode(IN2, OUTPUT);
|
||||
pinMode(IN3, OUTPUT);
|
||||
pinMode(IN4, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
Rtc.Begin();
|
||||
lcd.begin(16, 2); //set up the LCD's number of columns and rows:
|
||||
lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner
|
||||
ESP8266_init ();
|
||||
delay(1000); //delay 1000ms
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
dt = Rtc.DataTime(); //Get time from RTC module
|
||||
wifi_recv (); //Receive wifi data
|
||||
n++;
|
||||
if (n==5) //Loop 5 times
|
||||
{
|
||||
DHT11.read(DHT11PIN); //Get temperature and humidity from the DHT11
|
||||
now_temp = DHT11.temperature;
|
||||
//Serial.println(now_temp);
|
||||
LCD_display (); //Refresh the LCD1602
|
||||
n=0;
|
||||
}
|
||||
|
||||
Update_data (); //Update the temperature and humidity to APP
|
||||
SenorData_process (); //Check the data from each channel
|
||||
Control (); //Control motor according to the result of the previous function
|
||||
|
||||
delay (100);
|
||||
|
||||
}
|
||||
/***********************************************************
|
||||
*
|
||||
* The function of update the temperature and humidity
|
||||
*
|
||||
***********************************************************/
|
||||
void Update_data (void)
|
||||
{
|
||||
if (send_tmp_EN)
|
||||
{
|
||||
data1=(int)DHT11.temperature;
|
||||
data2=(int)DHT11.humidity;
|
||||
send_data ();
|
||||
}
|
||||
if (send_hum_EN)
|
||||
{
|
||||
data2=(int)DHT11.humidity;
|
||||
|
||||
send_data ();
|
||||
}
|
||||
if (send_DEBUG_EN||send_con_EN)
|
||||
{
|
||||
send_data ();
|
||||
}
|
||||
}
|
||||
/***********************************************************
|
||||
*
|
||||
* The function of Wifi data send
|
||||
*
|
||||
***********************************************************/
|
||||
void send_data (void)
|
||||
{
|
||||
if (send_tmp_EN==1||send_hum_EN==1||send_DEBUG_EN==1||send_con_EN)
|
||||
{
|
||||
_cell.print("AT+CIPSEND=0,126\r\n");
|
||||
unsigned long start;
|
||||
bool found;
|
||||
start = millis();
|
||||
while (millis()-start<250)
|
||||
{
|
||||
if(_cell.find(">")==true )
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(found)
|
||||
{
|
||||
_cell.print("HTTP/1.1 200 OK\r\nDate: Sat, 31 Dec 2005 23:59:59 GMT\r\nContent-Type: text/html;charset=ISO-8859-1\r\nContent-Length: 7\r\n\r\n"); // Data header
|
||||
|
||||
if (send_tmp_EN) // Updata Humidity and Temperature
|
||||
{
|
||||
_cell.print("tmp");
|
||||
_cell.print(data1);
|
||||
_cell.print(data2);
|
||||
send_tmp_EN=0;
|
||||
Serial.println ("Update");
|
||||
}
|
||||
if (send_DEBUG_EN) // Response control signal
|
||||
{
|
||||
_cell.print("debugen");
|
||||
send_DEBUG_EN=0;
|
||||
}
|
||||
if (send_con_EN) // Response detection of connection status
|
||||
{
|
||||
_cell.print("connect");
|
||||
send_con_EN=0;
|
||||
}
|
||||
_cell.print("\r\n");
|
||||
_cell.print("AT+CIPCLOSE=0\r\n"); // Close port
|
||||
}
|
||||
else
|
||||
{
|
||||
wifi.closeMux();
|
||||
}
|
||||
String data;
|
||||
start = millis();
|
||||
while (millis()-start<250)
|
||||
{
|
||||
if(_cell.available()>0)
|
||||
{
|
||||
char a =_cell.read();
|
||||
data=data+a;
|
||||
}
|
||||
if (data.indexOf("SEND OK")!=-1)
|
||||
{
|
||||
Serial.println("Send OK");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/***********************************************************
|
||||
*
|
||||
* The function of Wifi data receiving
|
||||
*
|
||||
***********************************************************/
|
||||
void wifi_recv (void)
|
||||
{
|
||||
char buf[100];
|
||||
int iLen = wifi.ReceiveMessage(buf);
|
||||
|
||||
if (iLen>0)
|
||||
{
|
||||
//Serial.println(buf);
|
||||
|
||||
if (buf[5]=='o'&&buf[6]=='n') // CH0 ON
|
||||
{
|
||||
|
||||
send_DEBUG_EN=1;
|
||||
if (MODE_0==1)
|
||||
{
|
||||
warning_1=1;
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("CH0 ON");
|
||||
|
||||
Serial.println("CH0 ON");
|
||||
delay (500);
|
||||
}
|
||||
}
|
||||
if (buf[5]=='o'&&buf[6]=='f'&&buf[7]=='f') // CH0 OFF
|
||||
{
|
||||
send_DEBUG_EN=1;
|
||||
if (MODE_0==1)
|
||||
{
|
||||
warning_1=0;
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("CH0 OFF");
|
||||
Serial.println("CH0 OFF");
|
||||
delay (500);
|
||||
}
|
||||
}
|
||||
if (buf[5]=='m'&&buf[6]=='o'&&buf[7]=='d'&&buf[8]=='e') // MODE CHANGE
|
||||
{
|
||||
|
||||
MODE_0=!MODE_0;
|
||||
lcd.clear();
|
||||
if (MODE_0==0) //Switch to automatic mode
|
||||
{
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("automatic");
|
||||
send_DEBUG_EN=1;
|
||||
Serial.println("Mode Change:automatic");
|
||||
delay (500);
|
||||
}
|
||||
else //Switch to manual mode
|
||||
{
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("manual");
|
||||
warning_1=0;
|
||||
send_DEBUG_EN=1;
|
||||
Serial.println("Mode Change:manual");
|
||||
delay (500);
|
||||
}
|
||||
}
|
||||
if (buf[5]=='c'&&buf[6]=='o'&&buf[7]=='n') // Check the connection status
|
||||
{
|
||||
send_con_EN=1;
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Connected");
|
||||
Serial.println("Connected");
|
||||
delay (500);
|
||||
}
|
||||
if (buf[5]=='t'&&buf[6]=='m'&&buf[7]=='p') // Temperature and Humidity update
|
||||
{
|
||||
send_tmp_EN=1;
|
||||
/*lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("temp update");
|
||||
Serial.println("TEMP");
|
||||
delay (500);*/
|
||||
delay (50);
|
||||
}
|
||||
}
|
||||
}
|
||||
/***********************************************************
|
||||
*
|
||||
* The function of data processing
|
||||
*
|
||||
***********************************************************/
|
||||
void SenorData_process (void)
|
||||
{
|
||||
if (now_temp>Temp_maxlimit&&(!MODE_0)) //Check temperature,High temperature will turn on the fan
|
||||
{
|
||||
warning_1=1;
|
||||
}
|
||||
if ((now_temp<Temp_minlimit||now_temp==Temp_minlimit)&&(!MODE_0)) //when the emperature back to safety level,the fan will be turned off
|
||||
{
|
||||
warning_1=0;
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
*
|
||||
* Control
|
||||
*
|
||||
***********************************************************/
|
||||
void Control (void)
|
||||
{
|
||||
if (warning_1==1)
|
||||
{
|
||||
motor1_start ();
|
||||
}
|
||||
else
|
||||
{
|
||||
motor1_stop ();
|
||||
}
|
||||
}
|
||||
/***********************************************************
|
||||
*
|
||||
* Motor control
|
||||
*
|
||||
***********************************************************/
|
||||
void motor1_start (void)
|
||||
{
|
||||
digitalWrite(IN1,HIGH);
|
||||
digitalWrite(IN2,LOW);
|
||||
}
|
||||
void motor1_stop (void)
|
||||
{
|
||||
digitalWrite(IN1,LOW);
|
||||
digitalWrite(IN2,LOW);
|
||||
}
|
||||
void motor2_start (void)
|
||||
{
|
||||
digitalWrite(IN3,HIGH);
|
||||
digitalWrite(IN4,LOW);
|
||||
}
|
||||
void motor2_stop (void)
|
||||
{
|
||||
digitalWrite(IN3,LOW);
|
||||
digitalWrite(IN4,LOW);
|
||||
}
|
||||
/***********************************************************
|
||||
*
|
||||
* Refresh the LCD1602
|
||||
*
|
||||
***********************************************************/
|
||||
void LCD_display (void)
|
||||
{
|
||||
char buffer[150]={0};
|
||||
Rtc.dateFormat("jS M y, h:ia", dt,buffer);
|
||||
n=0;
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(buffer+lcd_off1);
|
||||
lcd.setCursor(0, 1);
|
||||
Serial.println(DHT11.humidity);
|
||||
Serial.println(DHT11.temperature);
|
||||
lcd.print((float)DHT11.humidity, 2);// Print a message of Humidity to the LCD.
|
||||
lcd.print(" % "); // Print the unit of the centigrade temperature to the LCD.
|
||||
lcd.print((float)DHT11.temperature, 2);// Print a centigrade temperature to the LCD.
|
||||
lcd.print(" C "); // Print the unit of the centigrade temperature to the LCD.
|
||||
lcd_off1++;
|
||||
if (lcd_off1==3)
|
||||
{
|
||||
lcd_off1=0;
|
||||
}
|
||||
}
|
||||
/***********************************************************
|
||||
*
|
||||
* The initialization of ESP8266
|
||||
*
|
||||
***********************************************************/
|
||||
void ESP8266_init (void)
|
||||
{
|
||||
bool result=wifi.begin();
|
||||
if (result==1)
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("Module is ready");
|
||||
}
|
||||
else
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.print("Module not ready");
|
||||
}
|
||||
|
||||
bool b = wifi.Initialize(AP_STA, SSID, PASSWORD);
|
||||
lcd.clear();
|
||||
if(!b)
|
||||
{
|
||||
Serial.println("Init error");
|
||||
lcd.print("Init error");
|
||||
}
|
||||
else
|
||||
{
|
||||
lcd.print("reboot wifi OK");
|
||||
}
|
||||
delay(2000); //make sure the module can have enough time to get an IP address
|
||||
|
||||
String ipstring = wifi.showIP();
|
||||
int ip_dress_1=ipstring.indexOf('"');
|
||||
int ip_dress_2=ipstring.indexOf('"',ip_dress_1 + 1);
|
||||
int ip_dress_3=ipstring.indexOf('"',ip_dress_2 + 40);
|
||||
int ip_dress_4=ipstring.indexOf('"',ip_dress_3 + 1);
|
||||
Serial.print("APIP:"); //show the ip address of module
|
||||
Serial.println(ipstring.substring(ip_dress_1,ip_dress_2+1));
|
||||
Serial.print("STAIP:");
|
||||
Serial.println(ipstring.substring(ip_dress_3,ip_dress_4+1));
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(ipstring.substring(ip_dress_1,ip_dress_2+1));
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print(ipstring.substring(ip_dress_3,ip_dress_4+1));
|
||||
|
||||
delay(2000);
|
||||
wifi.confMux(1);
|
||||
delay(100);
|
||||
if(wifi.confServer(1,8089))
|
||||
{
|
||||
Serial.println("Server is set up");
|
||||
lcd.clear();
|
||||
lcd.print("Server is set up");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_3_digital_inputs.ino
|
||||
Description: use push buttons with digital inputs to turn
|
||||
an LED on and off
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
int ledPin = 5;
|
||||
int buttonApin = 9;
|
||||
int buttonBpin = 8;
|
||||
|
||||
byte leds = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(ledPin, OUTPUT);
|
||||
pinMode(buttonApin, INPUT_PULLUP);
|
||||
pinMode(buttonBpin, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (digitalRead(buttonApin) == LOW)
|
||||
{
|
||||
digitalWrite(ledPin, HIGH);
|
||||
}
|
||||
if (digitalRead(buttonBpin) == LOW)
|
||||
{
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_4_Controlling_a_RGB_LED_by_PWM.ino
|
||||
Description:Control the RGB LED emitting red, green, blue, yellow,
|
||||
white and purple light, then the RGB LED will be off,
|
||||
each state continues 1s, after repeating the above
|
||||
procedure.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
*************************************************************/
|
||||
int redPin = 11; // R petal on RGB LED module connected to digital pin 11
|
||||
int greenPin = 10; // G petal on RGB LED module connected to digital pin 10
|
||||
int bluePin = 9; // B petal on RGB LED module connected to digital pin 9
|
||||
void setup()
|
||||
{
|
||||
pinMode(redPin, OUTPUT); // sets the redPin to be an output
|
||||
pinMode(greenPin, OUTPUT); // sets the greenPin to be an output
|
||||
pinMode(bluePin, OUTPUT); // sets the bluePin to be an output
|
||||
}
|
||||
void loop() // run over and over again
|
||||
{
|
||||
// Basic colors:
|
||||
color(255, 0, 0); // turn the RGB LED red
|
||||
delay(1000); // delay for 1 second
|
||||
color(0,255, 0); // turn the RGB LED green
|
||||
delay(1000); // delay for 1 second
|
||||
color(0, 0, 255); // turn the RGB LED blue
|
||||
delay(1000); // delay for 1 second
|
||||
|
||||
// Example blended colors:
|
||||
color(255,255,0); // turn the RGB LED yellow
|
||||
delay(1000); // delay for 1 second
|
||||
color(255,255,255); // turn the RGB LED white
|
||||
delay(1000); // delay for 1 second
|
||||
color(128,0,255); // turn the RGB LED purple
|
||||
delay(1000); // delay for 1 second
|
||||
color(0,0,0); // turn the RGB LED off
|
||||
delay(1000); // delay for 1 second
|
||||
}
|
||||
|
||||
void color (unsigned char red, unsigned char green, unsigned char blue)// the color generating function
|
||||
{
|
||||
analogWrite(redPin, red); // PWM signal output
|
||||
analogWrite(greenPin, green); // PWM signal output
|
||||
analogWrite(bluePin, blue); // PWM signal output
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_5_Active_Buzzer.ino
|
||||
Description: Arduino 2560 Continuous beeps control buzzer.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
int buzzerPin=8; //definition digital 8 pins as pin to control the buzzer
|
||||
void setup()
|
||||
{
|
||||
pinMode(buzzerPin,OUTPUT); //Set digital 8 port mode, the OUTPUT for the output
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
digitalWrite(buzzerPin,HIGH); //Set PIN 8 feet as HIGH = 5 v
|
||||
delay(2000); //Set the delay time,2000ms
|
||||
digitalWrite(buzzerPin,LOW); //Set PIN 8 feet for LOW = 0 v
|
||||
delay(2000); //Set the delay time,2000ms
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_6_Play_the_Music.ino
|
||||
Description: you can hear the passive buzzer playing music,
|
||||
and you can see flickering LED follow the rhythm
|
||||
of the music at the same time.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
#define NTD0 -1 //bass 1# 2# 3# 4# 5# 6# 7#
|
||||
#define NTD1 294 // A 221 248 278 294 330 371 416
|
||||
#define NTD2 330 // B 248 278 294 330 371 416 467
|
||||
#define NTD3 350 // C 131 147 165 175 196 221 248
|
||||
#define NTD4 393 // D 147 165 175 196 221 248 278
|
||||
#define NTD5 441 // E 165 175 196 221 248 278 312
|
||||
#define NTD6 495 // F 175 196 221 234 262 294 330
|
||||
#define NTD7 556 // G 196 221 234 262 294 330 371
|
||||
|
||||
#define NTDL1 147 //Alto 1 2 3 4 5 6 7
|
||||
#define NTDL2 165 // A 441 495 556 589 661 742 833
|
||||
#define NTDL3 175 // B 495 556 624 661 742 833 935
|
||||
#define NTDL4 196 // C 262 294 330 350 393 441 495
|
||||
#define NTDL5 221 // D 294 330 350 393 441 495 556
|
||||
#define NTDL6 248 // E 330 350 393 441 495 556 624
|
||||
#define NTDL7 278 // F 350 393 441 495 556 624 661
|
||||
// G 393 441 495 556 624 661 742
|
||||
#define NTDH1 589
|
||||
#define NTDH2 661 //high pitch 1# 2# 3# 4# 5# 6# 7#
|
||||
#define NTDH3 700 // A 882 990 1112 1178 1322 1484 1665
|
||||
#define NTDH4 786 // B 990 1112 1178 1322 1484 1665 1869
|
||||
#define NTDH5 882 // C 525 589 661 700 786 882 990
|
||||
#define NTDH6 990 // D 589 661 700 786 882 990 1112
|
||||
#define NTDH7 112 // E 661 700 786 882 990 1112 1248
|
||||
//c pinlv // F 700 786 882 935 1049 1178 1322
|
||||
#define WHOLE 1 // G 786 882 990 1049 1178 1322 1484
|
||||
#define HALF 0.5
|
||||
#define QUARTER 0.25
|
||||
#define EIGHTH 0.25
|
||||
#define SIXTEENTH 0.625
|
||||
|
||||
int tune[]= //Music tones
|
||||
{
|
||||
NTD3,NTD3,NTD4,NTD5,
|
||||
NTD5,NTD4,NTD3,NTD2,
|
||||
NTD1,NTD1,NTD2,NTD3,
|
||||
NTD3,NTD2,NTD2,
|
||||
NTD3,NTD3,NTD4,NTD5,
|
||||
NTD5,NTD4,NTD3,NTD2,
|
||||
NTD1,NTD1,NTD2,NTD3,
|
||||
NTD2,NTD1,NTD1,
|
||||
NTD2,NTD2,NTD3,NTD1,
|
||||
NTD2,NTD3,NTD4,NTD3,NTD1,
|
||||
NTD2,NTD3,NTD4,NTD3,NTD2,
|
||||
NTD1,NTD2,NTDL5,NTD0,
|
||||
NTD3,NTD3,NTD4,NTD5,
|
||||
NTD5,NTD4,NTD3,NTD4,NTD2,
|
||||
NTD1,NTD1,NTD2,NTD3,
|
||||
NTD2,NTD1,NTD1
|
||||
};
|
||||
float durt[]= //Each musical tone delay time
|
||||
{
|
||||
1,1,1,1,
|
||||
1,1,1,1,
|
||||
1,1,1,1,
|
||||
1+0.5,0.5,1+1,
|
||||
1,1,1,1,
|
||||
1,1,1,1,
|
||||
1,1,1,1,
|
||||
1+0.5,0.5,1+1,
|
||||
1,1,1,1,
|
||||
1,0.5,0.5,1,1,
|
||||
1,0.5,0.5,1,1,
|
||||
1,1,1,1,
|
||||
1,1,1,1,
|
||||
1,1,1,0.5,0.5,
|
||||
1,1,1,1,
|
||||
1+0.5,0.5,1+1,
|
||||
};
|
||||
int length;
|
||||
int tonepin=6; //Buzzer connected digital pin 6
|
||||
int ledp=3; //LED connected digital pin 3
|
||||
void setup()
|
||||
{
|
||||
pinMode(tonepin,OUTPUT); //Digital pin 6 output mode
|
||||
pinMode(ledp,OUTPUT); //Digital pin 3 output mode
|
||||
length=sizeof(tune)/sizeof(tune[0]);//Calculate the total number of musical tones
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
for(int x=0;x<length;x++)
|
||||
{
|
||||
tone(tonepin,tune[x]); //Open buzzer
|
||||
digitalWrite(ledp, HIGH); //LED On
|
||||
delay(400*durt[x]); //Tone Delay. Note:400 can be replaced
|
||||
digitalWrite(ledp, LOW); //LED Off
|
||||
delay(100*durt[x]); //Tone Delay. Note:100 can be replaced
|
||||
noTone(tonepin); //Turn off the buzzer
|
||||
}
|
||||
delay(2000); //delay 2S
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_7_tilt_ball_switch.ino
|
||||
Description: Tilt switches to control the LED light on or off
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
int ledpin=11; //definition digital 11 pins as pin to control the LED
|
||||
int tiltSwitchpin=7; //Set the digital 7 to tilt switch interface
|
||||
int val; //Define variable val
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(ledpin,OUTPUT); //Define small lights interface for the output interface
|
||||
pinMode(tiltSwitchpin,INPUT_PULLUP);//define the tilt switch interface for input interface
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
val=digitalRead(tiltSwitchpin);//Read the number seven level value is assigned to val
|
||||
if(val==LOW) //Detect tilt switch is disconnected, the tilt switch when small lights go out
|
||||
{ digitalWrite(ledpin,LOW);} //Output low, LED OFF
|
||||
else //Detection of tilt switch is conduction, tilt the little lights up when the switch conduction +
|
||||
{ digitalWrite(ledpin,HIGH);} //Output high, LED ON
|
||||
}
|
||||
@ -0,0 +1,158 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_8_7-segement_display.ino
|
||||
Description:Segment display Numbers 0 to 9, each digital display
|
||||
1 second.After the cycle show
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
int a=4; //definition digital 4 pins as pin to control 'a' section(segment)
|
||||
int b=5; //definition digital 5 pins as pin to control 'b' section(segment)
|
||||
int c=7; //definition digital 7 pins as pin to control 'c' section(segment)
|
||||
int d=8;//definition digital 8 pins as pin to control 'd' section(segment)
|
||||
int e=9;//definition digital 9 pins as pin to control 'e' section(segment)
|
||||
int f=11; //definition digital 11 pins as pin to control 'f' section(segment)
|
||||
int g=10; //definition digital 10 pins as pin to control 'g' section(segment)
|
||||
int dp=6;//definition digital 6 pins as pin to control 'dp' section(segment)
|
||||
void digital_0(void) //Segment display digital 0
|
||||
{
|
||||
digitalWrite(a,LOW);
|
||||
digitalWrite(b,LOW);
|
||||
digitalWrite(c,LOW);
|
||||
digitalWrite(d,LOW);
|
||||
digitalWrite(e,LOW);
|
||||
digitalWrite(f,LOW);
|
||||
digitalWrite(g, HIGH);
|
||||
digitalWrite(dp,HIGH);
|
||||
}
|
||||
void digital_1(void) //Segment display digital 1
|
||||
{
|
||||
digitalWrite(a,HIGH);
|
||||
digitalWrite(b,LOW);
|
||||
digitalWrite(c,LOW);
|
||||
digitalWrite(d,HIGH);
|
||||
digitalWrite(e,HIGH);
|
||||
digitalWrite(f,HIGH);
|
||||
digitalWrite(g,HIGH);
|
||||
digitalWrite(dp,HIGH);
|
||||
}
|
||||
void digital_2(void) //Segment display digital 2
|
||||
{
|
||||
digitalWrite(a,LOW);
|
||||
digitalWrite(b,LOW);
|
||||
digitalWrite(c,HIGH);
|
||||
digitalWrite(d,LOW);
|
||||
digitalWrite(e,LOW);
|
||||
digitalWrite(f,HIGH);
|
||||
digitalWrite(g,LOW);
|
||||
digitalWrite(dp,HIGH);
|
||||
}
|
||||
void digital_3(void) //Segment display digital 3
|
||||
{
|
||||
digitalWrite(a,LOW);
|
||||
digitalWrite(b,LOW);
|
||||
digitalWrite(c,LOW);
|
||||
digitalWrite(d,LOW);
|
||||
digitalWrite(e,HIGH);
|
||||
digitalWrite(f,HIGH);
|
||||
digitalWrite(g,LOW);
|
||||
digitalWrite(dp,HIGH);
|
||||
}
|
||||
void digital_4(void) //Segment display digital 4
|
||||
{
|
||||
digitalWrite(a,HIGH);
|
||||
digitalWrite(b,LOW);
|
||||
digitalWrite(c,LOW);
|
||||
digitalWrite(d,HIGH);
|
||||
digitalWrite(e,HIGH);
|
||||
digitalWrite(f,LOW);
|
||||
digitalWrite(g,LOW);
|
||||
digitalWrite(dp,HIGH);
|
||||
}
|
||||
void digital_5(void) //Segment display digital 5
|
||||
{
|
||||
digitalWrite(a,LOW);
|
||||
digitalWrite(b,HIGH);
|
||||
digitalWrite(c,LOW);
|
||||
digitalWrite(d,LOW);
|
||||
digitalWrite(e,HIGH);
|
||||
digitalWrite(f,LOW);
|
||||
digitalWrite(g,LOW);
|
||||
digitalWrite(dp,HIGH);
|
||||
}
|
||||
void digital_6(void) //Segment display digital 6
|
||||
{
|
||||
digitalWrite(a,LOW);
|
||||
digitalWrite(b,HIGH);
|
||||
digitalWrite(c,LOW);
|
||||
digitalWrite(d,LOW);
|
||||
digitalWrite(e,LOW);
|
||||
digitalWrite(f,LOW);
|
||||
digitalWrite(g,LOW);
|
||||
digitalWrite(dp,HIGH);
|
||||
}
|
||||
void digital_7(void) //Segment display digital 7
|
||||
{
|
||||
digitalWrite(a,LOW);
|
||||
digitalWrite(b,LOW);
|
||||
digitalWrite(c,LOW);
|
||||
digitalWrite(d,HIGH);
|
||||
digitalWrite(e,HIGH);
|
||||
digitalWrite(f,HIGH);
|
||||
digitalWrite(g,HIGH);
|
||||
digitalWrite(dp,HIGH);
|
||||
}
|
||||
void digital_8(void) //Segment display digital 8
|
||||
{
|
||||
digitalWrite(a,LOW);
|
||||
digitalWrite(b,LOW);
|
||||
digitalWrite(c,LOW);
|
||||
digitalWrite(d,LOW);
|
||||
digitalWrite(e,LOW);
|
||||
digitalWrite(f,LOW);
|
||||
digitalWrite(g,LOW);
|
||||
digitalWrite(dp,HIGH);
|
||||
}
|
||||
void digital_9(void) //Segment display digital 9
|
||||
{
|
||||
digitalWrite(a,LOW);
|
||||
digitalWrite(b,LOW);
|
||||
digitalWrite(c,LOW);
|
||||
digitalWrite(d,LOW);
|
||||
digitalWrite(e,HIGH);
|
||||
digitalWrite(f,LOW);
|
||||
digitalWrite(g,LOW);
|
||||
digitalWrite(dp,HIGH);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
int i; //Define variables
|
||||
for(i=4;i<=11;i++)
|
||||
pinMode(i,OUTPUT); //Set up 4 ~ 11 pins to output mode
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
digital_0(); //Segment display digital 0
|
||||
delay(1000); //Delay 1s
|
||||
digital_1(); //Segment display digital 1
|
||||
delay(1000); //Delay 1s
|
||||
digital_2(); //Segment display digital 2
|
||||
delay(1000); //Delay 1s
|
||||
digital_3(); //Segment display digital 3
|
||||
delay(1000); //Delay 1s
|
||||
digital_4(); //Segment display digital 4
|
||||
delay(1000); //Delay 1s
|
||||
digital_5(); //Segment display digital 5
|
||||
delay(1000); //Delay 1s
|
||||
digital_6(); //Segment display digital 6
|
||||
delay(1000); //Delay 1s
|
||||
digital_7(); //Segment display digital 7
|
||||
delay(1000); //Delay 1s
|
||||
digital_8(); //Segment display digital 8
|
||||
delay(1000); //Delay 1s
|
||||
digital_9(); //Segment display digital 8
|
||||
delay(1000); //Delay 1s
|
||||
}
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
/***********************************************************
|
||||
File name: Lesson_9_Photoresistor.ino
|
||||
Description: measure light intensity using an Analog Input
|
||||
and use the level of light to control the
|
||||
number of LEDs to be lit.
|
||||
Website: www.uctronics.com
|
||||
E-mail: sales@uctronics.com
|
||||
Author: Lee
|
||||
Date: 2017/06/12
|
||||
***********************************************************/
|
||||
int lightPin = 0;
|
||||
//Pin connected to ST_CP of 74HC595
|
||||
int latchPin = 11;
|
||||
//Pin connected to SH_CP of 74HC595
|
||||
int clockPin = 12;
|
||||
////Pin connected to DS of 74HC595
|
||||
int dataPin = 8;
|
||||
|
||||
int leds = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(latchPin, OUTPUT);
|
||||
pinMode(dataPin, OUTPUT);
|
||||
pinMode(clockPin, OUTPUT);
|
||||
pinMode(lightPin, INPUT);
|
||||
}
|
||||
void updateShiftRegister()
|
||||
{
|
||||
digitalWrite(latchPin, LOW);
|
||||
shiftOut(dataPin, clockPin, LSBFIRST, leds);
|
||||
digitalWrite(latchPin, HIGH);
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
int reading = analogRead(lightPin);
|
||||
int numLEDSLit = reading / 57; //1023 / 9 / 2
|
||||
if (numLEDSLit > 8) numLEDSLit = 8;
|
||||
leds = 0; // no LEDs lit to start
|
||||
for (int i = 0; i < numLEDSLit; i++)
|
||||
{
|
||||
leds = leds + (1 << i); // sets the i'th bit
|
||||
}
|
||||
updateShiftRegister();
|
||||
delay (500);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1 @@
|
||||
# UCTRONICS_Arduino_kits
|
||||
@ -0,0 +1,12 @@
|
||||
DS1302 Arduino Library 1.0.1 / 01.12.2014
|
||||
=========================================
|
||||
|
||||
* Fix time & square wave battery backup
|
||||
* New function setBattery(bool timeBattery, bool squareBattery)
|
||||
* setBattery(true, false) is default called on begin()
|
||||
|
||||
DS1302 Arduino Library 1.0.0 / 27.04.2014
|
||||
=========================================
|
||||
|
||||
* First release
|
||||
|
||||
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, 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
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If 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 convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{one line to give the program's name and a brief idea of what it does.}
|
||||
Copyright (C) {year} {name of author}
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
@ -0,0 +1,54 @@
|
||||
Arduino-DS1302
|
||||
==============
|
||||
|
||||
DS1302 Real-Time Clock.
|
||||
|
||||
Date formats (Day)
|
||||
------------------
|
||||
|
||||
* d : Day of the month, 2 digits with leading zeros (01 to 31)
|
||||
* D : A textual representation of a day, three letters (Mon through Sun)
|
||||
* j : Day of the month without leading zeros (1 to 31)
|
||||
* l : A full textual representation of the day of the week (Sunday through Saturday)
|
||||
* N : ISO-8601 numeric representation of the day of the week (1 for Monday through 7 for Sunday)
|
||||
* S : English ordinal suffix for the day of the month, 2 characters (st, nd, rd or th. Works well with j)
|
||||
* w : Numeric representation of the day of the week (0 for Sunday through 6 for Saturday)
|
||||
* z : The day of the year (0 through 365)
|
||||
|
||||
Date formats (Month)
|
||||
--------------------
|
||||
|
||||
* F : A full textual representation of a month, such as January or March (January through December)
|
||||
* m : Numeric representation of a month, with leading zeros (01 through 12)
|
||||
* M : A short textual representation of a month, three letters (Jan through Dec)
|
||||
* n : Numeric representation of a month, without leading zeros (1 through 12)
|
||||
* t : Number of days in the given month (28 through 31)
|
||||
|
||||
Date formats (Year)
|
||||
-------------------
|
||||
|
||||
* L : Whether it's a leap year (1 if it is a leap year, 0 otherwise)
|
||||
* Y : A full numeric representation of a year, 4 digits (Examples: 1999 or 2003)
|
||||
* y : A two digit representation of a year (Examples: 99 or 03)
|
||||
|
||||
Date formats (Time)
|
||||
-------------------
|
||||
|
||||
* a : Lowercase Ante meridiem and Post meridiem (am or pm)
|
||||
* A : Uppercase Ante meridiem and Post meridiem (AM or PM)
|
||||
* g : 2-hour format of an hour without leading zeros (1 through 12)
|
||||
* G : 24-hour format of an hour without leading zeros (0 through 23)
|
||||
* h : 12-hour format of an hour with leading zeros (01 through 12)
|
||||
* H : 24-hour format of an hour with leading zeros (00 through 23)
|
||||
* i : Minutes with leading zeros (00 to 59)
|
||||
* s : Seconds, with leading zeros (00 through 59)
|
||||
|
||||
Dare formats (Full Date/Time)
|
||||
-----------------------------
|
||||
|
||||
* U : Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
|
||||
|
||||
Credits
|
||||
-------
|
||||
|
||||
First fork by adafruit https://github.com/adafruit/RTClib
|
||||
@ -0,0 +1,641 @@
|
||||
|
||||
|
||||
#ifndef __RTCDS1302_H__
|
||||
#define __RTCDS1302_H__
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "RtcDateTime.h"
|
||||
#include "RtcUtility.h"
|
||||
|
||||
|
||||
const uint8_t daysArray [] PROGMEM = { 31,28,31,30,31,30,31,31,30,31,30,31 };
|
||||
const uint8_t dowArray[] PROGMEM = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
|
||||
|
||||
//DS1302 Register Addresses
|
||||
const uint8_t DS1302_REG_TIMEDATE = 0x80;
|
||||
const uint8_t DS1302_REG_TIMEDATE_BURST = 0xBE;
|
||||
const uint8_t DS1302_REG_TCR = 0x90;
|
||||
const uint8_t DS1302_REG_RAM_BURST = 0xFE;
|
||||
const uint8_t DS1302_REG_RAMSTART = 0xc0;
|
||||
const uint8_t DS1302_REG_RAMEND = 0xfd;
|
||||
// ram read and write addresses are interleaved
|
||||
const uint8_t DS1302RamSize = 31;
|
||||
|
||||
|
||||
struct DateTime
|
||||
{
|
||||
uint16_t year;
|
||||
uint8_t month;
|
||||
uint8_t day;
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
uint8_t second;
|
||||
uint8_t dayOfWeek;
|
||||
uint32_t unixtime;
|
||||
};
|
||||
|
||||
// DS1302 Trickle Charge Control Register Bits
|
||||
enum DS1302TcrResistor {
|
||||
DS1302TcrResistor_Disabled = 0,
|
||||
DS1302TcrResistor_2KOhm = B00000001,
|
||||
DS1302TcrResistor_4KOhm = B00000010,
|
||||
DS1302TcrResistor_8KOhm = B00000011,
|
||||
DS1302TcrResistor_MASK = B00000011,
|
||||
};
|
||||
|
||||
enum DS1302TcrDiodes {
|
||||
DS1302TcrDiodes_None = 0,
|
||||
DS1302TcrDiodes_One = B00000100,
|
||||
DS1302TcrDiodes_Two = B00001000,
|
||||
DS1302TcrDiodes_Disabled = B00001100,
|
||||
DS1302TcrDiodes_MASK = B00001100,
|
||||
};
|
||||
|
||||
enum DS1302TcrStatus {
|
||||
DS1302TcrStatus_Enabled = B10100000,
|
||||
DS1302TcrStatus_Disabled = B01010000,
|
||||
DS1302TcrStatus_MASK = B11110000,
|
||||
};
|
||||
|
||||
const uint8_t DS1302Tcr_Disabled = DS1302TcrStatus_Disabled | DS1302TcrDiodes_Disabled | DS1302TcrResistor_Disabled;
|
||||
|
||||
// DS1302 Clock Halt Register & Bits
|
||||
const uint8_t DS1302_REG_CH = 0x80; // bit in the seconds register
|
||||
const uint8_t DS1302_CH = 7;
|
||||
|
||||
// Write Protect Register & Bits
|
||||
const uint8_t DS1302_REG_WP = 0x8E;
|
||||
const uint8_t DS1302_WP = 7;
|
||||
|
||||
template<class T_WIRE_METHOD> class RtcDS1302
|
||||
{
|
||||
public:
|
||||
RtcDS1302(T_WIRE_METHOD& wire) :
|
||||
_wire(wire)
|
||||
{
|
||||
}
|
||||
|
||||
void Begin()
|
||||
{
|
||||
_wire.begin();
|
||||
}
|
||||
|
||||
|
||||
void Begin(int sda, int scl)
|
||||
{
|
||||
_wire.begin(sda, scl);
|
||||
}
|
||||
|
||||
bool GetIsWriteProtected()
|
||||
{
|
||||
uint8_t wp = getReg(DS1302_REG_WP);
|
||||
return !!(wp & _BV(DS1302_WP));
|
||||
}
|
||||
|
||||
void SetIsWriteProtected(bool isWriteProtected)
|
||||
{
|
||||
uint8_t wp = getReg(DS1302_REG_WP);
|
||||
if (isWriteProtected)
|
||||
{
|
||||
wp |= _BV(DS1302_WP);
|
||||
}
|
||||
else
|
||||
{
|
||||
wp &= ~_BV(DS1302_WP);
|
||||
}
|
||||
setReg(DS1302_REG_WP, wp);
|
||||
}
|
||||
|
||||
bool IsDateTimeValid()
|
||||
{
|
||||
return GetDateTime().IsValid();
|
||||
}
|
||||
|
||||
bool GetIsRunning()
|
||||
{
|
||||
uint8_t ch = getReg(DS1302_REG_CH);
|
||||
return !(ch & _BV(DS1302_CH));
|
||||
}
|
||||
|
||||
void SetIsRunning(bool isRunning)
|
||||
{
|
||||
uint8_t ch = getReg(DS1302_REG_CH);
|
||||
if (isRunning)
|
||||
{
|
||||
ch &= ~_BV(DS1302_CH);
|
||||
}
|
||||
else
|
||||
{
|
||||
ch |= _BV(DS1302_CH);
|
||||
}
|
||||
setReg(DS1302_REG_CH, ch);
|
||||
}
|
||||
|
||||
uint8_t GetTrickleChargeSettings()
|
||||
{
|
||||
uint8_t setting = getReg(DS1302_REG_TCR);
|
||||
return setting;
|
||||
}
|
||||
|
||||
void SetTrickleChargeSettings(uint8_t setting)
|
||||
{
|
||||
if ((setting & DS1302TcrResistor_MASK) == DS1302TcrResistor_Disabled) {
|
||||
// invalid resistor setting, set to disabled
|
||||
setting = DS1302Tcr_Disabled;
|
||||
goto apply;
|
||||
}
|
||||
if ((setting & DS1302TcrDiodes_MASK) == DS1302TcrDiodes_Disabled ||
|
||||
(setting & DS1302TcrDiodes_MASK) == DS1302TcrDiodes_None) {
|
||||
// invalid diode setting, set to disabled
|
||||
setting = DS1302Tcr_Disabled;
|
||||
goto apply;
|
||||
}
|
||||
if ((setting & DS1302TcrStatus_MASK) != DS1302TcrStatus_Enabled) {
|
||||
// invalid status setting, set to disabled
|
||||
setting = DS1302Tcr_Disabled;
|
||||
goto apply;
|
||||
}
|
||||
|
||||
apply:
|
||||
setReg(DS1302_REG_TCR, setting);
|
||||
}
|
||||
// uint8_t dec2bcd(uint8_t dec)
|
||||
// {
|
||||
// return ((dec / 10) * 16) + (dec % 10);
|
||||
// }
|
||||
|
||||
|
||||
void setDateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second,const RtcDateTime& dt)
|
||||
{
|
||||
// set the date time
|
||||
_wire.beginTransmission(DS1302_REG_TIMEDATE_BURST);
|
||||
|
||||
_wire.write(Uint8ToBcd(second));
|
||||
_wire.write(Uint8ToBcd(minute));
|
||||
_wire.write(Uint8ToBcd(hour)); // 24 hour mode only
|
||||
_wire.write(Uint8ToBcd(day));
|
||||
_wire.write(Uint8ToBcd(month));
|
||||
// RTC Hardware Day of Week is 1-7, 1 = Monday
|
||||
// convert our Day of Week to Rtc Day of Week
|
||||
uint8_t rtcDow = RtcDateTime::ConvertDowToRtc(dt.DayOfWeek());
|
||||
_wire.write(Uint8ToBcd(rtcDow));
|
||||
_wire.write(Uint8ToBcd(year - 2000));
|
||||
_wire.write(0); // no write protect, as all of this is ignored if it is protected
|
||||
_wire.endTransmission();
|
||||
}
|
||||
|
||||
void SetDateTime(const RtcDateTime& dt)
|
||||
{
|
||||
// set the date time
|
||||
_wire.beginTransmission(DS1302_REG_TIMEDATE_BURST);
|
||||
|
||||
_wire.write(Uint8ToBcd(dt.Second()));
|
||||
_wire.write(Uint8ToBcd(dt.Minute()));
|
||||
_wire.write(Uint8ToBcd(dt.Hour())); // 24 hour mode only
|
||||
_wire.write(Uint8ToBcd(dt.Day()));
|
||||
_wire.write(Uint8ToBcd(dt.Month()));
|
||||
|
||||
// RTC Hardware Day of Week is 1-7, 1 = Monday
|
||||
// convert our Day of Week to Rtc Day of Week
|
||||
uint8_t rtcDow = RtcDateTime::ConvertDowToRtc(dt.DayOfWeek());
|
||||
|
||||
_wire.write(Uint8ToBcd(rtcDow));
|
||||
_wire.write(Uint8ToBcd(dt.Year() - 2000));
|
||||
_wire.write(0); // no write protect, as all of this is ignored if it is protected
|
||||
|
||||
_wire.endTransmission();
|
||||
}
|
||||
bool isLeapYear(uint16_t year)
|
||||
{
|
||||
return (year % 4 == 0);
|
||||
}
|
||||
char *strDaySufix(uint8_t day)
|
||||
{
|
||||
if (day % 10 == 1)
|
||||
{
|
||||
return "st";
|
||||
} else
|
||||
if (day % 10 == 2)
|
||||
{
|
||||
return "nd";
|
||||
}
|
||||
if (day % 10 == 3)
|
||||
{
|
||||
return "rd";
|
||||
}
|
||||
|
||||
return "th";
|
||||
}
|
||||
char *strAmPm(uint8_t hour, bool uppercase)
|
||||
{
|
||||
if (hour < 12)
|
||||
{
|
||||
if (uppercase)
|
||||
{
|
||||
return "AM";
|
||||
} else
|
||||
{
|
||||
return "am";
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (uppercase)
|
||||
{
|
||||
return "PM";
|
||||
} else
|
||||
{
|
||||
return "pm";
|
||||
}
|
||||
}
|
||||
}
|
||||
char *strMonth(uint8_t month)
|
||||
{
|
||||
switch (month) {
|
||||
case 1:
|
||||
return "January";
|
||||
break;
|
||||
case 2:
|
||||
return "February";
|
||||
break;
|
||||
case 3:
|
||||
return "March";
|
||||
break;
|
||||
case 4:
|
||||
return "April";
|
||||
break;
|
||||
case 5:
|
||||
return "May";
|
||||
break;
|
||||
case 6:
|
||||
return "June";
|
||||
break;
|
||||
case 7:
|
||||
return "July";
|
||||
break;
|
||||
case 8:
|
||||
return "August";
|
||||
break;
|
||||
case 9:
|
||||
return "September";
|
||||
break;
|
||||
case 10:
|
||||
return "October";
|
||||
break;
|
||||
case 11:
|
||||
return "November";
|
||||
break;
|
||||
case 12:
|
||||
return "December";
|
||||
break;
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
uint8_t hour12(uint8_t hour24)
|
||||
{
|
||||
if (hour24 == 0)
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
|
||||
if (hour24 > 12)
|
||||
{
|
||||
return (hour24 - 12);
|
||||
}
|
||||
|
||||
return hour24;
|
||||
}
|
||||
|
||||
uint8_t daysInMonth(uint16_t year, uint8_t month)
|
||||
{
|
||||
uint8_t days;
|
||||
|
||||
days = pgm_read_byte(daysArray + month - 1);
|
||||
|
||||
if ((month == 2) && isLeapYear(year))
|
||||
{
|
||||
++days;
|
||||
}
|
||||
|
||||
return days;
|
||||
}
|
||||
|
||||
long time2long(uint16_t days, uint8_t hours, uint8_t minutes, uint8_t seconds)
|
||||
{
|
||||
return ((days * 24L + hours) * 60 + minutes) * 60 + seconds;
|
||||
}
|
||||
uint32_t unixtime(void)
|
||||
{
|
||||
uint32_t u;
|
||||
|
||||
u = time2long(date2days(Timemessage.year, Timemessage.month, Timemessage.day), Timemessage.hour, Timemessage.minute, Timemessage.second);
|
||||
u += 946681200;
|
||||
|
||||
return u;
|
||||
}
|
||||
DateTime DataTime()
|
||||
{
|
||||
_wire.beginTransmission(DS1302_REG_TIMEDATE_BURST | THREEWIRE_READFLAG);
|
||||
uint8_t second = BcdToUint8(_wire.read() & 0x7F);
|
||||
uint8_t minute = BcdToUint8(_wire.read());
|
||||
uint8_t hour = BcdToBin24Hour(_wire.read());
|
||||
uint8_t day = BcdToUint8(_wire.read());
|
||||
uint8_t month = BcdToUint8(_wire.read());
|
||||
|
||||
uint8_t dayOfWeek=BcdToUint8(_wire.read());
|
||||
|
||||
uint16_t year = BcdToUint8(_wire.read()) + 2000;
|
||||
|
||||
_wire.read(); // throwing away write protect flag
|
||||
_wire.endTransmission();
|
||||
Timemessage.year=year;
|
||||
Timemessage.month=month;
|
||||
Timemessage.day=day;
|
||||
Timemessage.hour=hour;
|
||||
Timemessage.minute=minute;
|
||||
Timemessage.second=second;
|
||||
Timemessage.dayOfWeek=dayOfWeek;
|
||||
Timemessage.unixtime = unixtime();
|
||||
return Timemessage;
|
||||
}
|
||||
RtcDateTime GetDateTime()
|
||||
{
|
||||
_wire.beginTransmission(DS1302_REG_TIMEDATE_BURST | THREEWIRE_READFLAG);
|
||||
|
||||
uint8_t second = BcdToUint8(_wire.read() & 0x7F);
|
||||
uint8_t minute = BcdToUint8(_wire.read());
|
||||
uint8_t hour = BcdToBin24Hour(_wire.read());
|
||||
uint8_t dayOfMonth = BcdToUint8(_wire.read());
|
||||
uint8_t month = BcdToUint8(_wire.read());
|
||||
|
||||
uint8_t week=BcdToUint8(_wire.read()); // throwing away day of week as we calculate it
|
||||
|
||||
uint16_t year = BcdToUint8(_wire.read()) + 2000;
|
||||
|
||||
_wire.read(); // throwing away write protect flag
|
||||
|
||||
_wire.endTransmission();
|
||||
return RtcDateTime(year, month, dayOfMonth, hour, minute, second);
|
||||
}
|
||||
uint16_t date2days(uint16_t year, uint8_t month, uint8_t day)
|
||||
{
|
||||
year = year - 2000;
|
||||
|
||||
uint16_t days16 = day;
|
||||
|
||||
for (uint8_t i = 1; i < month; ++i)
|
||||
{
|
||||
days16 += pgm_read_byte(daysArray + i - 1);
|
||||
}
|
||||
|
||||
if ((month == 2) && isLeapYear(year))
|
||||
{
|
||||
++days16;
|
||||
}
|
||||
|
||||
return days16 + 365 * year + (year + 3) / 4 - 1;
|
||||
}
|
||||
uint16_t dayInYear(uint16_t year, uint8_t month, uint8_t day)
|
||||
{
|
||||
uint16_t fromDate;
|
||||
uint16_t toDate;
|
||||
|
||||
fromDate = date2days(year, 1, 1);
|
||||
toDate = date2days(year, month, day);
|
||||
|
||||
return (toDate - fromDate);
|
||||
}
|
||||
char *strDayOfWeek(uint8_t dayOfWeek)
|
||||
{
|
||||
switch (dayOfWeek) {
|
||||
case 1:
|
||||
return "Monday";
|
||||
break;
|
||||
case 2:
|
||||
return "Tuesday";
|
||||
break;
|
||||
case 3:
|
||||
return "Wednesday";
|
||||
break;
|
||||
case 4:
|
||||
return "Thursday";
|
||||
break;
|
||||
case 5:
|
||||
return "Friday";
|
||||
break;
|
||||
case 6:
|
||||
return "Saturday";
|
||||
break;
|
||||
case 7:
|
||||
return "Sunday";
|
||||
break;
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
char* dateFormat(const char* dateFormat, DateTime dt,char* buffer)
|
||||
{
|
||||
|
||||
buffer[0] = 0;
|
||||
char helper[11]={0};
|
||||
while (*dateFormat != '\0')
|
||||
{
|
||||
switch (dateFormat[0])
|
||||
{
|
||||
// Day decoder
|
||||
case 'd':
|
||||
sprintf(helper, "%02d", dt.day);
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
case 'j':
|
||||
sprintf(helper, "%d", dt.day);
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
case 'l':
|
||||
strcat(buffer, (const char *)strDayOfWeek(dt.dayOfWeek));
|
||||
break;
|
||||
case 'D':
|
||||
strncat(buffer, strDayOfWeek(dt.dayOfWeek), 3);
|
||||
break;
|
||||
case 'N':
|
||||
sprintf(helper, "%d", dt.dayOfWeek);
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
case 'w':
|
||||
sprintf(helper, "%d", (dt.dayOfWeek + 7) % 7);
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
case 'z':
|
||||
sprintf(helper, "%d", dayInYear(dt.year, dt.month, dt.day));
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
case 'S':
|
||||
strcat(buffer, (const char *)strDaySufix(dt.day));
|
||||
break;
|
||||
|
||||
// Month decoder
|
||||
case 'm':
|
||||
sprintf(helper, "%02d", dt.month);
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
case 'n':
|
||||
sprintf(helper, "%d", dt.month);
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
case 'F':
|
||||
strcat(buffer, (const char *)strMonth(dt.month));
|
||||
break;
|
||||
case 'M':
|
||||
strncat(buffer, (const char *)strMonth(dt.month), 3);
|
||||
break;
|
||||
case 't':
|
||||
sprintf(helper, "%d", daysInMonth(dt.year, dt.month));
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
|
||||
// Year decoder
|
||||
case 'Y':
|
||||
sprintf(helper, "%d", dt.year);
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
case 'y': sprintf(helper, "%02d", dt.year-2000);
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
case 'L':
|
||||
sprintf(helper, "%d", isLeapYear(dt.year));
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
|
||||
// Hour decoder
|
||||
case 'H':
|
||||
sprintf(helper, "%02d", dt.hour);
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
case 'G':
|
||||
sprintf(helper, "%d", dt.hour);
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
case 'h':
|
||||
sprintf(helper, "%02d", hour12(dt.hour));
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
case 'g':
|
||||
sprintf(helper, "%d", hour12(dt.hour));
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
case 'A':
|
||||
strcat(buffer, (const char *)strAmPm(dt.hour, true));
|
||||
break;
|
||||
case 'a':
|
||||
strcat(buffer, (const char *)strAmPm(dt.hour, false));
|
||||
break;
|
||||
|
||||
// Minute decoder
|
||||
case 'i':
|
||||
sprintf(helper, "%02d", dt.minute);
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
|
||||
// Second decoder
|
||||
case 's':
|
||||
sprintf(helper, "%02d", dt.second);
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
|
||||
// Misc decoder
|
||||
case 'U':
|
||||
sprintf(helper, "%lu", dt.unixtime);
|
||||
strcat(buffer, (const char *)helper);
|
||||
break;
|
||||
|
||||
default:
|
||||
strncat(buffer, dateFormat, 1);
|
||||
break;
|
||||
}
|
||||
dateFormat++;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
void SetMemory(uint8_t memoryAddress, uint8_t value)
|
||||
{
|
||||
// memory addresses interleaved read and write addresses
|
||||
// so we need to calculate the offset
|
||||
uint8_t address = memoryAddress * 2 + DS1302_REG_RAMSTART;
|
||||
if (address <= DS1302_REG_RAMEND)
|
||||
{
|
||||
setReg(address, value);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t GetMemory(uint8_t memoryAddress)
|
||||
{
|
||||
uint8_t value = 0;
|
||||
// memory addresses interleaved read and write addresses
|
||||
// so we need to calculate the offset
|
||||
uint8_t address = memoryAddress * 2 + DS1302_REG_RAMSTART;
|
||||
if (address <= DS1302_REG_RAMEND)
|
||||
{
|
||||
value = getReg(address);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
uint8_t SetMemory(const uint8_t* pValue, uint8_t countBytes)
|
||||
{
|
||||
uint8_t countWritten = 0;
|
||||
|
||||
_wire.beginTransmission(DS1302_REG_RAM_BURST);
|
||||
|
||||
while (countBytes > 0 && countWritten < DS1302RamSize)
|
||||
{
|
||||
_wire.write(*pValue++);
|
||||
countBytes--;
|
||||
countWritten++;
|
||||
}
|
||||
|
||||
_wire.endTransmission();
|
||||
|
||||
return countWritten;
|
||||
}
|
||||
|
||||
uint8_t GetMemory(uint8_t* pValue, uint8_t countBytes)
|
||||
{
|
||||
uint8_t countRead = 0;
|
||||
|
||||
_wire.beginTransmission(DS1302_REG_RAM_BURST | THREEWIRE_READFLAG);
|
||||
|
||||
while (countBytes > 0 && countRead < DS1302RamSize)
|
||||
{
|
||||
*pValue++ = _wire.read();
|
||||
countRead++;
|
||||
countBytes--;
|
||||
}
|
||||
|
||||
_wire.endTransmission();
|
||||
|
||||
return countRead;
|
||||
}
|
||||
|
||||
private:
|
||||
T_WIRE_METHOD& _wire;
|
||||
DateTime Timemessage;
|
||||
|
||||
uint8_t getReg(uint8_t regAddress)
|
||||
{
|
||||
|
||||
_wire.beginTransmission(regAddress | THREEWIRE_READFLAG);
|
||||
uint8_t regValue = _wire.read();
|
||||
_wire.endTransmission();
|
||||
return regValue;
|
||||
}
|
||||
|
||||
void setReg(uint8_t regAddress, uint8_t regValue)
|
||||
{
|
||||
_wire.beginTransmission(regAddress);
|
||||
_wire.write(regValue);
|
||||
_wire.endTransmission();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __RTCDS1302_H__
|
||||
@ -0,0 +1,211 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "RtcDateTime.h"
|
||||
|
||||
const uint8_t c_daysInMonth[] PROGMEM = { 31,28,31,30,31,30,31,31,30,31,30,31 };
|
||||
|
||||
RtcDateTime::RtcDateTime(uint32_t secondsFrom2000)
|
||||
{
|
||||
_initWithSecondsFrom2000<uint32_t>(secondsFrom2000);
|
||||
}
|
||||
|
||||
bool RtcDateTime::IsValid() const
|
||||
{
|
||||
// this just tests the most basic validity of the value ranges
|
||||
// and valid leap years
|
||||
// It does not check any time zone or daylight savings time
|
||||
if ((_month > 0 && _month < 13) &&
|
||||
(_dayOfMonth > 0 && _dayOfMonth < 32) &&
|
||||
(_hour < 24) &&
|
||||
(_minute < 60) &&
|
||||
(_second < 60))
|
||||
{
|
||||
// days in a month tests
|
||||
//
|
||||
if (_month == 2)
|
||||
{
|
||||
if (_dayOfMonth > 29)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (_dayOfMonth > 28)
|
||||
{
|
||||
// leap day
|
||||
// check year to make sure its a leap year
|
||||
uint16_t year = Year();
|
||||
|
||||
if ((year % 4) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((year % 100) == 0 &&
|
||||
(year % 400) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (_dayOfMonth == 31)
|
||||
{
|
||||
if ((((_month - 1) % 7) % 2) == 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t StringToUint8(const char* pString)
|
||||
{
|
||||
uint8_t value = 0;
|
||||
|
||||
// skip leading 0 and spaces
|
||||
while ('0' == *pString || *pString == ' ')
|
||||
{
|
||||
pString++;
|
||||
}
|
||||
|
||||
// calculate number until we hit non-numeral char
|
||||
while ('0' <= *pString && *pString <= '9')
|
||||
{
|
||||
value *= 10;
|
||||
value += *pString - '0';
|
||||
pString++;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
RtcDateTime::RtcDateTime(const char* date, const char* time)
|
||||
{
|
||||
// sample input: date = "Dec 06 2009", time = "12:34:56"
|
||||
_yearFrom2000 = StringToUint8(date + 9);
|
||||
// Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
|
||||
switch (date[0])
|
||||
{
|
||||
case 'J':
|
||||
if ( date[1] == 'a' )
|
||||
_month = 1;
|
||||
else if ( date[2] == 'n' )
|
||||
_month = 6;
|
||||
else
|
||||
_month = 7;
|
||||
break;
|
||||
case 'F':
|
||||
_month = 2;
|
||||
break;
|
||||
case 'A':
|
||||
_month = date[1] == 'p' ? 4 : 8;
|
||||
break;
|
||||
case 'M':
|
||||
_month = date[2] == 'r' ? 3 : 5;
|
||||
break;
|
||||
case 'S':
|
||||
_month = 9;
|
||||
break;
|
||||
case 'O':
|
||||
_month = 10;
|
||||
break;
|
||||
case 'N':
|
||||
_month = 11;
|
||||
break;
|
||||
case 'D':
|
||||
_month = 12;
|
||||
break;
|
||||
}
|
||||
_dayOfMonth = StringToUint8(date + 4);
|
||||
_hour = StringToUint8(time);
|
||||
_minute = StringToUint8(time + 3);
|
||||
_second = StringToUint8(time + 6);
|
||||
}
|
||||
|
||||
template <typename T> T DaysSinceFirstOfYear2000(uint16_t year, uint8_t month, uint8_t dayOfMonth)
|
||||
{
|
||||
T days = dayOfMonth;
|
||||
for (uint8_t indexMonth = 1; indexMonth < month; ++indexMonth)
|
||||
{
|
||||
days += pgm_read_byte(c_daysInMonth + indexMonth - 1);
|
||||
}
|
||||
if (month > 2 && year % 4 == 0)
|
||||
{
|
||||
days++;
|
||||
}
|
||||
return days + 365 * year + (year + 3) / 4 - 1;
|
||||
}
|
||||
|
||||
template <typename T> T SecondsIn(T days, uint8_t hours, uint8_t minutes, uint8_t seconds)
|
||||
{
|
||||
return ((days * 24L + hours) * 60 + minutes) * 60 + seconds;
|
||||
}
|
||||
|
||||
uint8_t RtcDateTime::DayOfWeek() const
|
||||
{
|
||||
uint16_t days = DaysSinceFirstOfYear2000<uint16_t>(_yearFrom2000, _month, _dayOfMonth);
|
||||
return (days + 6) % 7; // Jan 1, 2000 is a Saturday, i.e. returns 6
|
||||
}
|
||||
|
||||
// 32-bit time; as seconds since 1/1/2000
|
||||
uint32_t RtcDateTime::TotalSeconds() const
|
||||
{
|
||||
uint16_t days = DaysSinceFirstOfYear2000<uint16_t>(_yearFrom2000, _month, _dayOfMonth);
|
||||
return SecondsIn<uint32_t>(days, _hour, _minute, _second);
|
||||
}
|
||||
|
||||
// 64-bit time; as seconds since 1/1/2000
|
||||
uint64_t RtcDateTime::TotalSeconds64() const
|
||||
{
|
||||
uint32_t days = DaysSinceFirstOfYear2000<uint32_t>(_yearFrom2000, _month, _dayOfMonth);
|
||||
return SecondsIn<uint64_t>(days, _hour, _minute, _second);
|
||||
}
|
||||
|
||||
// total days since 1/1/2000
|
||||
uint16_t RtcDateTime::TotalDays() const
|
||||
{
|
||||
return DaysSinceFirstOfYear2000<uint16_t>(_yearFrom2000, _month, _dayOfMonth);
|
||||
}
|
||||
|
||||
void RtcDateTime::InitWithIso8601(const char* date)
|
||||
{
|
||||
// sample input: date = "Sat, 06 Dec 2009 12:34:56 GMT"
|
||||
_yearFrom2000 = StringToUint8(date + 13);
|
||||
// Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
|
||||
switch (date[8])
|
||||
{
|
||||
case 'J':
|
||||
if (date[1 + 8] == 'a')
|
||||
_month = 1;
|
||||
else if (date[2 + 8] == 'n')
|
||||
_month = 6;
|
||||
else
|
||||
_month = 7;
|
||||
break;
|
||||
case 'F':
|
||||
_month = 2;
|
||||
break;
|
||||
case 'A':
|
||||
_month = date[1 + 8] == 'p' ? 4 : 8;
|
||||
break;
|
||||
case 'M':
|
||||
_month = date[2 + 8] == 'r' ? 3 : 5;
|
||||
break;
|
||||
case 'S':
|
||||
_month = 9;
|
||||
break;
|
||||
case 'O':
|
||||
_month = 10;
|
||||
break;
|
||||
case 'N':
|
||||
_month = 11;
|
||||
break;
|
||||
case 'D':
|
||||
_month = 12;
|
||||
break;
|
||||
}
|
||||
_dayOfMonth = StringToUint8(date + 5);
|
||||
_hour = StringToUint8(date + 17);
|
||||
_minute = StringToUint8(date + 20);
|
||||
_second = StringToUint8(date + 23);
|
||||
}
|
||||
@ -0,0 +1,185 @@
|
||||
|
||||
|
||||
#ifndef __RTCDATETIME_H__
|
||||
#define __RTCDATETIME_H__
|
||||
|
||||
// ESP32 complains if not included
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
enum DayOfWeek
|
||||
{
|
||||
DayOfWeek_Sunday = 0,
|
||||
DayOfWeek_Monday,
|
||||
DayOfWeek_Tuesday,
|
||||
DayOfWeek_Wednesday,
|
||||
DayOfWeek_Thursday,
|
||||
DayOfWeek_Friday,
|
||||
DayOfWeek_Saturday,
|
||||
};
|
||||
|
||||
const uint16_t c_OriginYear = 2000;
|
||||
const uint32_t c_Epoch32OfOriginYear = 946684800;
|
||||
extern const uint8_t c_daysInMonth[] PROGMEM;
|
||||
|
||||
class RtcDateTime
|
||||
{
|
||||
public:
|
||||
RtcDateTime(uint32_t secondsFrom2000 = 0);
|
||||
RtcDateTime(uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t dayOfMonth,
|
||||
uint8_t hour,
|
||||
uint8_t minute,
|
||||
uint8_t second) :
|
||||
_yearFrom2000((year >= c_OriginYear) ? year - c_OriginYear : year),
|
||||
_month(month),
|
||||
_dayOfMonth(dayOfMonth),
|
||||
_hour(hour),
|
||||
_minute(minute),
|
||||
_second(second)
|
||||
{
|
||||
}
|
||||
|
||||
// RtcDateTime compileDateTime(__DATE__, __TIME__);
|
||||
RtcDateTime(const char* date, const char* time);
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
uint16_t Year() const
|
||||
{
|
||||
return c_OriginYear + _yearFrom2000;
|
||||
}
|
||||
uint8_t Month() const
|
||||
{
|
||||
return _month;
|
||||
}
|
||||
uint8_t Day() const
|
||||
{
|
||||
return _dayOfMonth;
|
||||
}
|
||||
uint8_t Hour() const
|
||||
{
|
||||
return _hour;
|
||||
}
|
||||
uint8_t Minute() const
|
||||
{
|
||||
return _minute;
|
||||
}
|
||||
uint8_t Second() const
|
||||
{
|
||||
return _second;
|
||||
}
|
||||
// 0 = Sunday, 1 = Monday, ... 6 = Saturday
|
||||
uint8_t DayOfWeek() const;
|
||||
|
||||
// 32-bit time; as seconds since 1/1/2000
|
||||
uint32_t TotalSeconds() const;
|
||||
|
||||
// 64-bit time; as seconds since 1/1/2000
|
||||
uint64_t TotalSeconds64() const;
|
||||
|
||||
// total days since 1/1/2000
|
||||
uint16_t TotalDays() const;
|
||||
|
||||
// add seconds
|
||||
void operator += (uint32_t seconds)
|
||||
{
|
||||
RtcDateTime after = RtcDateTime( TotalSeconds() + seconds );
|
||||
*this = after;
|
||||
}
|
||||
|
||||
// remove seconds
|
||||
void operator -= (uint32_t seconds)
|
||||
{
|
||||
RtcDateTime before = RtcDateTime( TotalSeconds() - seconds );
|
||||
*this = before;
|
||||
}
|
||||
|
||||
// allows for comparisons to just work (==, <, >, <=, >=, !=)
|
||||
operator uint32_t() const
|
||||
{
|
||||
return TotalSeconds();
|
||||
}
|
||||
|
||||
// Epoch32 support
|
||||
uint32_t Epoch32Time() const
|
||||
{
|
||||
return TotalSeconds() + c_Epoch32OfOriginYear;
|
||||
}
|
||||
void InitWithEpoch32Time(uint32_t time)
|
||||
{
|
||||
_initWithSecondsFrom2000<uint32_t>(time - c_Epoch32OfOriginYear);
|
||||
}
|
||||
|
||||
// Epoch64 support
|
||||
uint64_t Epoch64Time() const
|
||||
{
|
||||
return TotalSeconds64() + c_Epoch32OfOriginYear;
|
||||
}
|
||||
void InitWithEpoch64Time(uint64_t time)
|
||||
{
|
||||
_initWithSecondsFrom2000<uint64_t>(time - c_Epoch32OfOriginYear);
|
||||
}
|
||||
|
||||
void InitWithIso8601(const char* date);
|
||||
|
||||
|
||||
// convert our Day of Week to Rtc Day of Week
|
||||
// RTC Hardware Day of Week is 1-7, 1 = Monday
|
||||
static uint8_t ConvertDowToRtc(uint8_t dow)
|
||||
{
|
||||
if (dow == 0)
|
||||
{
|
||||
dow = 7;
|
||||
}
|
||||
return dow;
|
||||
}
|
||||
|
||||
// convert Rtc Day of Week to our Day of Week
|
||||
static uint8_t ConvertRtcToDow(uint8_t rtcDow)
|
||||
{
|
||||
return (rtcDow % 7);
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t _yearFrom2000;
|
||||
uint8_t _month;
|
||||
uint8_t _dayOfMonth;
|
||||
uint8_t _hour;
|
||||
uint8_t _minute;
|
||||
uint8_t _second;
|
||||
|
||||
template <typename T> void _initWithSecondsFrom2000(T secondsFrom2000)
|
||||
{
|
||||
_second = secondsFrom2000 % 60;
|
||||
T timeFrom2000 = secondsFrom2000 / 60;
|
||||
_minute = timeFrom2000 % 60;
|
||||
timeFrom2000 /= 60;
|
||||
_hour = timeFrom2000 % 24;
|
||||
T days = timeFrom2000 / 24;
|
||||
T leapDays;
|
||||
|
||||
for (_yearFrom2000 = 0;; ++_yearFrom2000)
|
||||
{
|
||||
leapDays = (_yearFrom2000 % 4 == 0) ? 1 : 0;
|
||||
if (days < 365U + leapDays)
|
||||
break;
|
||||
days -= 365 + leapDays;
|
||||
}
|
||||
for (_month = 1;; ++_month)
|
||||
{
|
||||
uint8_t daysPerMonth = pgm_read_byte(c_daysInMonth + _month - 1);
|
||||
if (leapDays && _month == 2)
|
||||
daysPerMonth++;
|
||||
if (days < daysPerMonth)
|
||||
break;
|
||||
days -= daysPerMonth;
|
||||
}
|
||||
_dayOfMonth = days + 1;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // __RTCDATETIME_H__
|
||||
@ -0,0 +1,34 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "RtcUtility.h"
|
||||
|
||||
uint8_t BcdToUint8(uint8_t val)
|
||||
{
|
||||
return val - 6 * (val >> 4);
|
||||
}
|
||||
|
||||
uint8_t Uint8ToBcd(uint8_t val)
|
||||
{
|
||||
return val + 6 * (val / 10);
|
||||
}
|
||||
|
||||
uint8_t BcdToBin24Hour(uint8_t bcdHour)
|
||||
{
|
||||
uint8_t hour;
|
||||
if (bcdHour & 0x40)
|
||||
{
|
||||
// 12 hour mode, convert to 24
|
||||
bool isPm = ((bcdHour & 0x20) != 0);
|
||||
|
||||
hour = BcdToUint8(bcdHour & 0x1f);
|
||||
if (isPm)
|
||||
{
|
||||
hour += 12;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hour = BcdToUint8(bcdHour);
|
||||
}
|
||||
return hour;
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
|
||||
#ifndef __RTCUTILITY_H__
|
||||
#define __RTCUTILITY_H__
|
||||
|
||||
// ESP32 complains if not included
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
// Arduino has no standard for attributing methods used for ISRs
|
||||
// even though some platforms require it, so to simplify the problem
|
||||
// for end users, this provides a standard ISR_ATTR
|
||||
#if !defined(ISR_ATTR)
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#define ISR_ATTR ICACHE_RAM_ATTR
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
#define ISR_ATTR ICACHE_RAM_ATTR
|
||||
#else
|
||||
#define ISR_ATTR
|
||||
#endif
|
||||
|
||||
#endif // !defined(ISR_ATTR)
|
||||
|
||||
|
||||
// for some reason, the DUE board support does not define this, even though other non AVR archs do
|
||||
#ifndef _BV
|
||||
#define _BV(b) (1UL << (b))
|
||||
#endif
|
||||
|
||||
extern uint8_t BcdToUint8(uint8_t val);
|
||||
extern uint8_t Uint8ToBcd(uint8_t val);
|
||||
extern uint8_t BcdToBin24Hour(uint8_t bcdHour);
|
||||
|
||||
#endif // __RTCUTILITY_H__
|
||||
@ -0,0 +1,99 @@
|
||||
#pragma once
|
||||
|
||||
//ThreeWire command Read/Write flag
|
||||
const uint8_t THREEWIRE_READFLAG = 0x01;
|
||||
|
||||
class ThreeWire
|
||||
{
|
||||
public:
|
||||
ThreeWire(uint8_t ioPin, uint8_t clkPin, uint8_t cePin) :
|
||||
_ioPin(ioPin),
|
||||
_clkPin(clkPin),
|
||||
_cePin(cePin)
|
||||
{
|
||||
}
|
||||
|
||||
void begin() {
|
||||
resetPins();
|
||||
}
|
||||
|
||||
void end() {
|
||||
resetPins();
|
||||
}
|
||||
|
||||
void beginTransmission(uint8_t command) {
|
||||
digitalWrite(_cePin, LOW); // default, not enabled
|
||||
pinMode(_cePin, OUTPUT);
|
||||
|
||||
digitalWrite(_clkPin, LOW); // default, clock low
|
||||
pinMode(_clkPin, OUTPUT);
|
||||
|
||||
pinMode(_ioPin, OUTPUT);
|
||||
|
||||
digitalWrite(_cePin, HIGH); // start the session
|
||||
delayMicroseconds(4); // tCC = 4us
|
||||
|
||||
write(command, (command & THREEWIRE_READFLAG) == THREEWIRE_READFLAG);
|
||||
}
|
||||
|
||||
void endTransmission() {
|
||||
digitalWrite(_cePin, LOW);
|
||||
delayMicroseconds(4); // tCWH = 4us
|
||||
}
|
||||
|
||||
void write(uint8_t value, bool isDataRequestCommand = false) {
|
||||
for (uint8_t bit = 0; bit < 8; bit++) {
|
||||
digitalWrite(_ioPin, value & 0x01);
|
||||
delayMicroseconds(1); // tDC = 200ns
|
||||
|
||||
// clock up, data is read by DS1302
|
||||
digitalWrite(_clkPin, HIGH);
|
||||
delayMicroseconds(1); // tCH = 1000ns, tCDH = 800ns
|
||||
|
||||
// for the last bit before a read
|
||||
// Set IO line for input before the clock down
|
||||
if (bit == 7 && isDataRequestCommand) {
|
||||
pinMode(_ioPin, INPUT);
|
||||
}
|
||||
|
||||
digitalWrite(_clkPin, LOW);
|
||||
delayMicroseconds(1); // tCL=1000ns, tCDD=800ns
|
||||
|
||||
value >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t read() {
|
||||
uint8_t value = 0;
|
||||
|
||||
for (uint8_t bit = 0; bit < 8; bit++) {
|
||||
// first bit is present on io pin, so only clock the other
|
||||
// bits
|
||||
value |= (digitalRead(_ioPin) << bit);
|
||||
|
||||
// Clock up, prepare for next
|
||||
digitalWrite(_clkPin, HIGH);
|
||||
delayMicroseconds(1);
|
||||
|
||||
// Clock down, value is ready after some time.
|
||||
digitalWrite(_clkPin, LOW);
|
||||
delayMicroseconds(1); // tCL=1000ns, tCDD=800ns
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private:
|
||||
const uint8_t _ioPin;
|
||||
const uint8_t _clkPin;
|
||||
const uint8_t _cePin;
|
||||
|
||||
void resetPins() {
|
||||
// just making sure they are in a default low power use state
|
||||
// as required state is set when transmissions are started
|
||||
// three wire devices have internal pull downs so they will be low
|
||||
pinMode(_clkPin, INPUT);
|
||||
pinMode(_ioPin, INPUT);
|
||||
pinMode(_cePin, INPUT);
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,50 @@
|
||||
/*
|
||||
DS3231: Real-Time Clock. Date Format
|
||||
GIT: https://github.com/UCTRONICS/UCTRONICS_Arduino_kits
|
||||
Web: www.uctronics.com
|
||||
*/
|
||||
|
||||
#include <ThreeWire.h>
|
||||
#include <RtcDS1302.h>
|
||||
|
||||
ThreeWire myWire(4,5,2); // IO, SCLK, CE
|
||||
RtcDS1302<ThreeWire> Rtc(myWire);
|
||||
|
||||
#define countof(a) (sizeof(a) / sizeof(a[0]))
|
||||
DateTime dt;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(57600);
|
||||
Rtc.Begin();
|
||||
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
|
||||
Rtc.setDateTime(2017, 6, 13, 16, 29, 3,compiled);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
char buffer[150]={0};
|
||||
dt = Rtc.DataTime();
|
||||
Serial.print("Long number format: ");
|
||||
Rtc.dateFormat("d-m-Y H:i:s", dt,buffer);
|
||||
Serial.println(buffer);
|
||||
Serial.print("Long format with month name: ");
|
||||
Rtc.dateFormat("d F Y H:i:s", dt,buffer);
|
||||
Serial.println(buffer);
|
||||
Serial.print("Short format witch 12h mode: ");
|
||||
Rtc.dateFormat("jS M y, h:ia", dt,buffer);
|
||||
Serial.println(buffer);
|
||||
Serial.print("Today is: ");
|
||||
Rtc.dateFormat("l, z", dt,buffer);
|
||||
Serial.print(buffer);
|
||||
Serial.println(" days of the year.");
|
||||
Serial.print("Actual month has: ");
|
||||
Rtc.dateFormat("t", dt,buffer);
|
||||
Serial.print(buffer);
|
||||
Serial.println(" days.");
|
||||
Serial.print("Unixtime: ");
|
||||
Rtc.dateFormat("U", dt,buffer);
|
||||
Serial.println(buffer);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
/*
|
||||
DS3231: Real-Time Clock. Simple example
|
||||
Read more: www.jarzebski.pl/arduino/komponenty/zegar-czasu-rzeczywistego-rtc-ds3231.html
|
||||
GIT: https://github.com/UCTRONICS/UCTRONICS_Arduino_kits
|
||||
Web: www.uctronics.com
|
||||
*/
|
||||
|
||||
#include <ThreeWire.h>
|
||||
#include <RtcDS1302.h>
|
||||
|
||||
ThreeWire myWire(4,5,2); // IO, SCLK, CE
|
||||
RtcDS1302<ThreeWire> Rtc(myWire);
|
||||
|
||||
#define countof(a) (sizeof(a) / sizeof(a[0]))
|
||||
DateTime dt;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Rtc.Begin();
|
||||
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
|
||||
Rtc.setDateTime(2017, 6, 13, 16, 29, 3,compiled);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
dt = Rtc.DataTime();
|
||||
|
||||
// For leading zero look to DS3231_dateformat example
|
||||
|
||||
Serial.print("Raw data: ");
|
||||
Serial.print(dt.year); Serial.print("-");
|
||||
Serial.print(dt.month); Serial.print("-");
|
||||
Serial.print(dt.day); Serial.print(" ");
|
||||
Serial.print(dt.hour); Serial.print(":");
|
||||
Serial.print(dt.minute); Serial.print(":");
|
||||
Serial.print(dt.second); Serial.println("");
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
//
|
||||
// FILE: dht11.cpp
|
||||
// VERSION: 0.4.1
|
||||
// PURPOSE: DHT11 Temperature & Humidity Sensor library for Arduino
|
||||
// LICENSE: GPL v3 (http://www.gnu.org/licenses/gpl.html)
|
||||
//
|
||||
// DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf
|
||||
//
|
||||
// HISTORY:
|
||||
// George Hadjikyriacou - Original version (??)
|
||||
// Mod by SimKard - Version 0.2 (24/11/2010)
|
||||
// Mod by Rob Tillaart - Version 0.3 (28/03/2011)
|
||||
// + added comments
|
||||
// + removed all non DHT11 specific code
|
||||
// + added references
|
||||
// Mod by Rob Tillaart - Version 0.4 (17/03/2012)
|
||||
// + added 1.0 support
|
||||
// Mod by Rob Tillaart - Version 0.4.1 (19/05/2012)
|
||||
// + added error codes
|
||||
//
|
||||
|
||||
#include "dht11.h"
|
||||
|
||||
// Return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int dht11::read(int pin)
|
||||
{
|
||||
// BUFFER TO RECEIVE
|
||||
uint8_t bits[5];
|
||||
uint8_t cnt = 7;
|
||||
uint8_t idx = 0;
|
||||
|
||||
// EMPTY BUFFER
|
||||
for (int i=0; i< 5; i++) bits[i] = 0;
|
||||
|
||||
// REQUEST SAMPLE
|
||||
pinMode(pin, OUTPUT);
|
||||
digitalWrite(pin, LOW);
|
||||
delay(18);
|
||||
digitalWrite(pin, HIGH);
|
||||
delayMicroseconds(40);
|
||||
pinMode(pin, INPUT);
|
||||
|
||||
// ACKNOWLEDGE or TIMEOUT
|
||||
unsigned int loopCnt = 10000;
|
||||
while(digitalRead(pin) == LOW)
|
||||
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
|
||||
|
||||
loopCnt = 10000;
|
||||
while(digitalRead(pin) == HIGH)
|
||||
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
|
||||
|
||||
// READ OUTPUT - 40 BITS => 5 BYTES or TIMEOUT
|
||||
for (int i=0; i<40; i++)
|
||||
{
|
||||
loopCnt = 10000;
|
||||
while(digitalRead(pin) == LOW)
|
||||
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
|
||||
|
||||
unsigned long t = micros();
|
||||
|
||||
loopCnt = 10000;
|
||||
while(digitalRead(pin) == HIGH)
|
||||
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
|
||||
|
||||
if ((micros() - t) > 40) bits[idx] |= (1 << cnt);
|
||||
if (cnt == 0) // next byte?
|
||||
{
|
||||
cnt = 7; // restart at MSB
|
||||
idx++; // next byte!
|
||||
}
|
||||
else cnt--;
|
||||
}
|
||||
|
||||
// WRITE TO RIGHT VARS
|
||||
// as bits[1] and bits[3] are allways zero they are omitted in formulas.
|
||||
humidity = bits[0];
|
||||
temperature = bits[2];
|
||||
|
||||
uint8_t sum = bits[0] + bits[2];
|
||||
|
||||
if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM;
|
||||
return DHTLIB_OK;
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
@ -0,0 +1,28 @@
|
||||
|
||||
|
||||
#ifndef dht11_h
|
||||
#define dht11_h
|
||||
|
||||
#if defined(ARDUINO) && (ARDUINO >= 100)
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#endif
|
||||
|
||||
#define DHT11LIB_VERSION "0.4.1"
|
||||
|
||||
#define DHTLIB_OK 0
|
||||
#define DHTLIB_ERROR_CHECKSUM -1
|
||||
#define DHTLIB_ERROR_TIMEOUT -2
|
||||
|
||||
class dht11
|
||||
{
|
||||
public:
|
||||
int read(int pin);
|
||||
int humidity;
|
||||
int temperature;
|
||||
};
|
||||
#endif
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
@ -0,0 +1,91 @@
|
||||
/*
|
||||
dht11
|
||||
GIT: https://github.com/UCTRONICS/UCTRONICS_Arduino_kits
|
||||
Web: www.uctronics.com
|
||||
*/
|
||||
#include <dht11.h>
|
||||
|
||||
dht11 DHT11;
|
||||
|
||||
#define DHT11PIN 2
|
||||
double Fahrenheit(double celsius)
|
||||
{
|
||||
return 1.8 * celsius + 32;
|
||||
}
|
||||
double Kelvin(double celsius)
|
||||
{
|
||||
return celsius + 273.15;
|
||||
}
|
||||
double dewPoint(double celsius, double humidity)
|
||||
{
|
||||
double A0= 373.15/(273.15 + celsius);
|
||||
double SUM = -7.90298 * (A0-1);
|
||||
SUM += 5.02808 * log10(A0);
|
||||
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
|
||||
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
|
||||
SUM += log10(1013.246);
|
||||
double VP = pow(10, SUM-3) * humidity;
|
||||
double T = log(VP/0.61078); // temp var
|
||||
return (241.88 * T) / (17.558-T);
|
||||
}
|
||||
double dewPointFast(double celsius, double humidity)
|
||||
{
|
||||
double a = 17.271;
|
||||
double b = 237.7;
|
||||
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
|
||||
double Td = (b * temp) / (a - temp);
|
||||
return Td;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("DHT11 TEST PROGRAM ");
|
||||
Serial.print("LIBRARY VERSION: ");
|
||||
Serial.println(DHT11LIB_VERSION);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("\n");
|
||||
|
||||
int chk = DHT11.read(DHT11PIN);
|
||||
|
||||
Serial.print("Read sensor: ");
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
Serial.println("OK");
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
Serial.println("Checksum error");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT:
|
||||
Serial.println("Time out error");
|
||||
break;
|
||||
default:
|
||||
Serial.println("Unknown error");
|
||||
break;
|
||||
}
|
||||
|
||||
Serial.print("Humidity (%): ");
|
||||
Serial.println((float)DHT11.humidity, 2);
|
||||
|
||||
Serial.print("Temperature (oC): ");
|
||||
Serial.println((float)DHT11.temperature, 2);
|
||||
|
||||
Serial.print("Temperature (oF): ");
|
||||
Serial.println(Fahrenheit(DHT11.temperature), 2);
|
||||
|
||||
Serial.print("Temperature (K): ");
|
||||
Serial.println(Kelvin(DHT11.temperature), 2);
|
||||
|
||||
Serial.print("Dew Point (oC): ");
|
||||
Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));
|
||||
|
||||
Serial.print("Dew PointFast (oC): ");
|
||||
Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
# Warning!
|
||||
|
||||
This library has been discarded. A new library named WeeESP8266 is recommended, which is more easy-to-use for users.
|
||||
WeeESP8266 can be downloaded at <https://github.com/itead/ITEADLIB_Arduino_WeeESP8266>.
|
||||
|
||||
# ESP8266 library #
|
||||
|
||||
When you use with UNO board, uncomment the follow line in uartWIFI.h.
|
||||
|
||||
#define UNO
|
||||
|
||||
When you use with MEGA board, uncomment the follow line in uartWIFI.h.
|
||||
|
||||
#define MEGA
|
||||
|
||||
## Connection: ##
|
||||
When you use it with UNO board, the connection should be like these:
|
||||
|
||||
ESP8266_TX->D0
|
||||
|
||||
ESP8266_RX->D1
|
||||
|
||||
ESP8266_CHPD->3.3V
|
||||
|
||||
ESP8266_VCC->3.3V
|
||||
|
||||
ESP8266_GND->GND
|
||||
|
||||
FTDI_RX->D3 //The baud rate of software serial can't be higher that 19200, so we use software serial as a debug port
|
||||
|
||||
FTDI_TX->D2
|
||||
|
||||
When you use it with MEGA board, the connection should be like these:
|
||||
|
||||
ESP8266_TX->RX1(D19)
|
||||
|
||||
ESP8266_RX->TX1(D18)
|
||||
|
||||
ESP8266_CH_PD->3.3V
|
||||
|
||||
ESP8266_VCC->3.3V
|
||||
|
||||
ESP8266_GND->GND
|
||||
|
||||
When you want to output the debug information, please use DebugSerial. For example,
|
||||
|
||||
DebugSerial.println("hello");
|
||||
|
||||
## Attention ##
|
||||
|
||||
**Note1**: The size of message from ESP8266 is too big for arduino sometimes, so the library can't receive the whole buffer because
|
||||
the size of the hardware serial buffer which is defined in HardwareSerial.h is too small.
|
||||
|
||||
Open the file from \arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.h.
|
||||
See the follow line in the HardwareSerial.h file.
|
||||
|
||||
#define SERIAL_BUFFER_SIZE 64
|
||||
|
||||
The default size of the buffer is 64. Change it into a bigger number, like 256 or more.
|
||||
|
||||
The SRAM size of mega is bigger than UNO's, so it is better to use MEGA board to communicate with ESP8266.
|
||||
|
||||
|
||||
**BUG**: When you use this library and receive the http package, it might miss some characters because the library can't process so much data in the same time.
|
||||
|
||||
**Created by Stan Lee(Lizq@iteadstudio.com)**
|
||||
|
||||
2014/10/8
|
||||
|
||||
**Modified version**
|
||||
|
||||
V1.0 released the first version of ESP8266 library
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,102 @@
|
||||
|
||||
/*
|
||||
GIT: https://github.com/UCTRONICS/UCTRONICS_Arduino_kits
|
||||
Web: www.uctronics.com
|
||||
|
||||
ESP8266 library
|
||||
|
||||
When you use with UNO board, uncomment the follow line in uartWIFI.h.
|
||||
#define UNO
|
||||
|
||||
When you use with MEGA board, uncomment the follow line in uartWIFI.h.
|
||||
#define MEGA
|
||||
|
||||
Connection:
|
||||
When you use it with UNO board, the connection should be like these:
|
||||
ESP8266_TX->D0
|
||||
ESP8266_RX->D1
|
||||
ESP8266_CH_PD->3.3V
|
||||
ESP8266_VCC->3.3V
|
||||
ESP8266_GND->GND
|
||||
|
||||
FTDI_RX->D3 //The baud rate of software serial can't be higher that 19200, so we use software serial as a debug port
|
||||
FTDI_TX->D2
|
||||
|
||||
When you use it with MEGA board, the connection should be like these:
|
||||
ESP8266_TX->RX1(D19)
|
||||
ESP8266_RX->TX1(D18)
|
||||
ESP8266_CH_PD->3.3V
|
||||
ESP8266_VCC->3.3V
|
||||
ESP8266_GND->GND
|
||||
|
||||
When you want to output the debug information, please use DebugSerial. For example,
|
||||
|
||||
DebugSerial.println("hello");
|
||||
|
||||
Note: The size of message from ESP8266 is too big for arduino sometimes, so the library can't receive the whole buffer because
|
||||
the size of the hardware serial buffer which is defined in HardwareSerial.h is too small.
|
||||
|
||||
Open the file from \arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.h.
|
||||
See the follow line in the HardwareSerial.h file.
|
||||
|
||||
#define SERIAL_BUFFER_SIZE 64
|
||||
|
||||
The default size of the buffer is 64. Change it into a bigger number, like 256 or more.
|
||||
|
||||
*/
|
||||
#define SSID "Itead_1(Public)"
|
||||
#define PASSWORD "27955416"
|
||||
|
||||
|
||||
#include "uartWIFI.h"
|
||||
#include <SoftwareSerial.h>
|
||||
WIFI wifi;
|
||||
|
||||
extern int chlID; //client id(0-4)
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
wifi.begin();
|
||||
bool b = wifi.Initialize(STA, SSID, PASSWORD);
|
||||
if(!b)
|
||||
{
|
||||
DebugSerial.println("Init error");
|
||||
}
|
||||
delay(8000); //make sure the module can have enough time to get an IP address
|
||||
String ipstring = wifi.showIP();
|
||||
DebugSerial.println(ipstring); //show the ip address of module
|
||||
|
||||
delay(5000);
|
||||
wifi.confMux(1);
|
||||
delay(100);
|
||||
if(wifi.confServer(1,8080))
|
||||
DebugSerial.println("Server is set up");
|
||||
|
||||
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
|
||||
char buf[100];
|
||||
int iLen = wifi.ReceiveMessage(buf);
|
||||
if(iLen > 0)
|
||||
{
|
||||
//if receive a "HELLO", send a "HELLO BACK" back to the client
|
||||
if (strcmp(buf, "HELLO") == 0)
|
||||
{
|
||||
DebugSerial.print("Get a message from id ");
|
||||
DebugSerial.print(chlID);
|
||||
DebugSerial.println(":");
|
||||
DebugSerial.println(buf);
|
||||
|
||||
DebugSerial.print("Send a message back to id ");
|
||||
DebugSerial.print(chlID);
|
||||
DebugSerial.println(":");
|
||||
DebugSerial.println("HELLO BACK");
|
||||
wifi.Send(chlID,"HELLO BACK");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,99 @@
|
||||
/*
|
||||
GIT: https://github.com/UCTRONICS/UCTRONICS_Arduino_kits
|
||||
Web: www.uctronics.com
|
||||
ESP8266 library
|
||||
|
||||
When you use with UNO board, uncomment the follow line in uartWIFI.h.
|
||||
#define UNO
|
||||
|
||||
When you use with MEGA board, uncomment the follow line in uartWIFI.h.
|
||||
#define MEGA
|
||||
|
||||
Connection:
|
||||
When you use it with UNO board, the connection should be like these:
|
||||
ESP8266_TX->D0
|
||||
ESP8266_RX->D1
|
||||
ESP8266_CH_PD->3.3V
|
||||
ESP8266_VCC->3.3V
|
||||
ESP8266_GND->GND
|
||||
|
||||
FTDI_RX->D3 //The baud rate of software serial can't be higher that 19200, so we use software serial as a debug port
|
||||
FTDI_TX->D2
|
||||
|
||||
When you use it with MEGA board, the connection should be like these:
|
||||
ESP8266_TX->RX1(D19)
|
||||
ESP8266_RX->TX1(D18)
|
||||
ESP8266_CH_PD->3.3V
|
||||
ESP8266_VCC->3.3V
|
||||
ESP8266_GND->GND
|
||||
|
||||
When you want to output the debug information, please use DebugSerial. For example,
|
||||
|
||||
DebugSerial.println("hello");
|
||||
|
||||
|
||||
Note: The size of message from ESP8266 is too big for arduino sometimes, so the library can't receive the whole buffer because
|
||||
the size of the hardware serial buffer which is defined in HardwareSerial.h is too small.
|
||||
|
||||
Open the file from \arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.h.
|
||||
See the follow line in the HardwareSerial.h file.
|
||||
|
||||
#define SERIAL_BUFFER_SIZE 64
|
||||
|
||||
The default size of the buffer is 64. Change it into a bigger number, like 256 or more.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#define SSID "Itead_1(Public)"
|
||||
#define PASSWORD "27955416"
|
||||
|
||||
|
||||
#include "uartWIFI.h"
|
||||
#include <SoftwareSerial.h>
|
||||
WIFI wifi;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
wifi.begin();
|
||||
bool b = wifi.Initialize(STA, SSID, PASSWORD);
|
||||
if(!b)
|
||||
{
|
||||
DebugSerial.println("Init error");
|
||||
}
|
||||
delay(8000); //make sure the module can have enough time to get an IP address
|
||||
//String ipstring = wifi.showIP();
|
||||
//DebugSerial.println(ipstring); //show the ip address of module
|
||||
|
||||
//delay(5000);
|
||||
wifi.ipConfig(UDP, "172.16.1.16", 80); //Connect to your pc
|
||||
|
||||
DebugSerial.println("setup done..");
|
||||
wifi.Send("setup done..");
|
||||
pinMode(13,OUTPUT);
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
|
||||
char buf[100];
|
||||
int iLen = wifi.ReceiveMessage(buf);
|
||||
if(iLen > 0)
|
||||
{
|
||||
//if you receive "HIGH" message, set the D13 to high voltage; and vice versa
|
||||
if (strcmp(buf, "HIGH") == 0)
|
||||
{
|
||||
digitalWrite(13, HIGH);
|
||||
}
|
||||
else if (strcmp(buf, "LOW") == 0)
|
||||
{
|
||||
digitalWrite(13, LOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,125 @@
|
||||
/*
|
||||
GIT: https://github.com/UCTRONICS/UCTRONICS_Arduino_kits
|
||||
Web: www.uctronics.com
|
||||
ESP8266 library
|
||||
|
||||
When you use with UNO board, uncomment the follow line in uartWIFI.h.
|
||||
#define UNO
|
||||
|
||||
When you use with MEGA board, uncomment the follow line in uartWIFI.h.
|
||||
#define MEGA
|
||||
|
||||
Connection:
|
||||
When you use it with UNO board, the connection should be like these:
|
||||
ESP8266_TX->D0
|
||||
ESP8266_RX->D1
|
||||
ESP8266_CH_PD->3.3V
|
||||
ESP8266_VCC->3.3V
|
||||
ESP8266_GND->GND
|
||||
|
||||
FTDI_RX->D3 //The baud rate of software serial can't be higher that 19200, so we use software serial as a debug port
|
||||
FTDI_TX->D2
|
||||
|
||||
When you use it with MEGA board, the connection should be like these:
|
||||
ESP8266_TX->RX1(D19)
|
||||
ESP8266_RX->TX1(D18)
|
||||
ESP8266_CH_PD->3.3V
|
||||
ESP8266_VCC->3.3V
|
||||
ESP8266_GND->GND
|
||||
|
||||
When you want to output the debug information, please use DebugSerial. For example,
|
||||
|
||||
DebugSerial.println("hello");
|
||||
|
||||
|
||||
Note: The size of message from ESP8266 is too big for arduino sometimes, so the library can't receive the whole buffer because
|
||||
the size of the hardware serial buffer which is defined in HardwareSerial.h is too small.
|
||||
|
||||
Open the file from \arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.h.
|
||||
See the follow line in the HardwareSerial.h file.
|
||||
|
||||
#define SERIAL_BUFFER_SIZE 64
|
||||
|
||||
The default size of the buffer is 64. Change it into a bigger number, like 256 or more.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#define SSID "Itead_1(Public)"
|
||||
#define PASSWORD "27955416"
|
||||
|
||||
#define server "220.181.111.85" //baidu.com
|
||||
|
||||
|
||||
#include "uartWIFI.h"
|
||||
#include <SoftwareSerial.h>
|
||||
WIFI wifi;
|
||||
|
||||
|
||||
|
||||
|
||||
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||
boolean lastConnected = false; // state of the connection last time through the main loop
|
||||
const unsigned long postingInterval = 8*1000; // delay between updates, in milliseconds
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
wifi.begin();
|
||||
bool b = wifi.Initialize(STA, SSID, PASSWORD);
|
||||
if(!b)
|
||||
{
|
||||
DebugSerial.println("Init error");
|
||||
|
||||
}
|
||||
delay(8000);
|
||||
String ipstring = wifi.showIP();
|
||||
|
||||
DebugSerial.println(ipstring);
|
||||
|
||||
pinMode(13,OUTPUT);
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
char message[320];
|
||||
// if you're not connected, and ten seconds have passed since
|
||||
// your last connection, then connect again and send data:
|
||||
if((millis() - lastConnectionTime > postingInterval)) {
|
||||
httpRequest();
|
||||
}
|
||||
|
||||
// if there's incoming data from the net connection.
|
||||
// send it out the serial port. This is for debugging
|
||||
// purposes only:
|
||||
if(wifi.ReceiveMessage(message))
|
||||
{
|
||||
DebugSerial.println(message);
|
||||
}
|
||||
|
||||
|
||||
delay(10);
|
||||
}
|
||||
|
||||
// this method makes a HTTP connection to the server:
|
||||
void httpRequest() {
|
||||
// if there's a successful connection:
|
||||
if (wifi.ipConfig(TCP,server, 80)) {
|
||||
DebugSerial.println("connecting...");
|
||||
// send the HTTP PUT request:
|
||||
|
||||
//wifi.Send("GET / HTTP/1.0\r\n\r\n");
|
||||
wifi.Send("GET / HTTP/1.0\r\n\r\n");
|
||||
// note the time that the connection was made:
|
||||
lastConnectionTime = millis();
|
||||
}
|
||||
else {
|
||||
// if you couldn't make a connection:
|
||||
DebugSerial.println("connection failed");
|
||||
DebugSerial.println("disconnecting.");
|
||||
wifi.closeMux();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,122 @@
|
||||
/*
|
||||
GIT: https://github.com/UCTRONICS/UCTRONICS_Arduino_kits
|
||||
Web: www.uctronics.com
|
||||
ESP8266 library
|
||||
|
||||
When you use with UNO board, uncomment the follow line in uartWIFI.h.
|
||||
#define UNO
|
||||
|
||||
When you use with MEGA board, uncomment the follow line in uartWIFI.h.
|
||||
#define MEGA
|
||||
|
||||
Connection:
|
||||
When you use it with UNO board, the connection should be like these:
|
||||
ESP8266_TX->D0
|
||||
ESP8266_RX->D1
|
||||
ESP8266_CH_PD->3.3V
|
||||
ESP8266_VCC->3.3V
|
||||
ESP8266_GND->GND
|
||||
|
||||
FTDI_RX->D3 //The baud rate of software serial can't be higher that 19200, so we use software serial as a debug port
|
||||
FTDI_TX->D2
|
||||
|
||||
When you use it with MEGA board, the connection should be like these:
|
||||
ESP8266_TX->RX1(D19)
|
||||
ESP8266_RX->TX1(D18)
|
||||
ESP8266_CH_PD->3.3V
|
||||
ESP8266_VCC->3.3V
|
||||
ESP8266_GND->GND
|
||||
|
||||
When you want to output the debug information, please use DebugSerial. For example,
|
||||
|
||||
DebugSerial.println("hello");
|
||||
|
||||
|
||||
Note: The size of message from ESP8266 is too big for arduino sometimes, so the library can't receive the whole buffer because
|
||||
the size of the hardware serial buffer which is defined in HardwareSerial.h is too small.
|
||||
|
||||
Open the file from \arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.h.
|
||||
See the follow line in the HardwareSerial.h file.
|
||||
|
||||
#define SERIAL_BUFFER_SIZE 64
|
||||
|
||||
The default size of the buffer is 64. Change it into a bigger number, like 256 or more.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#define SSID "Itead_1(Public)"
|
||||
#define PASSWORD "27955416"
|
||||
|
||||
|
||||
#include "uartWIFI.h"
|
||||
#include <SoftwareSerial.h>
|
||||
WIFI wifi;
|
||||
|
||||
extern int chlID;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
wifi.begin();
|
||||
bool b = wifi.Initialize(STA, SSID, PASSWORD);
|
||||
if(!b)
|
||||
{
|
||||
DebugSerial.println("Init error");
|
||||
}
|
||||
delay(8000); //make sure the module can have enough time to get an IP address
|
||||
String ipstring = wifi.showIP();
|
||||
DebugSerial.println(ipstring); //show the ip address of module
|
||||
|
||||
delay(1000);
|
||||
wifi.confMux(1);
|
||||
delay(100);
|
||||
if(wifi.confServer(1,80))
|
||||
DebugSerial.println("Server is set up");
|
||||
|
||||
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
|
||||
char buf[500];
|
||||
int iLen = wifi.ReceiveMessage(buf);
|
||||
if(iLen > 0)
|
||||
{
|
||||
|
||||
DebugSerial.print(buf);
|
||||
delay(100);
|
||||
|
||||
String cmd;
|
||||
cmd = "HTTP/1.1 200 OK\r\n";
|
||||
cmd += "Content-Type: text/html\r\n";
|
||||
cmd += "Connection: close\r\n";
|
||||
cmd += "Refresh: 8\r\n";
|
||||
cmd += "\r\n";
|
||||
cmd += "<!DOCTYPE HTML>\r\n";
|
||||
cmd += "<html>\r\n";
|
||||
for(int analogChannel = 0; analogChannel < 6; analogChannel++)
|
||||
{
|
||||
int sensorReading = analogRead(analogChannel);
|
||||
cmd += "analog input ";
|
||||
cmd += String(analogChannel);
|
||||
cmd += " is ";
|
||||
cmd += String(sensorReading);
|
||||
cmd += "<br />\r\n";
|
||||
|
||||
}
|
||||
cmd += "<html>\r\n";
|
||||
|
||||
wifi.Send(chlID,cmd);
|
||||
delay(300);
|
||||
wifi.closeMux(chlID);
|
||||
delay(1000);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
/*
|
||||
GIT: https://github.com/UCTRONICS/UCTRONICS_Arduino_kits
|
||||
Web: www.uctronics.com
|
||||
ESP8266 library
|
||||
|
||||
When you use with UNO board, uncomment the follow line in uartWIFI.h.
|
||||
#define UNO
|
||||
|
||||
When you use with MEGA board, uncomment the follow line in uartWIFI.h.
|
||||
#define MEGA
|
||||
|
||||
Connection:
|
||||
When you use it with UNO board, the connection should be like these:
|
||||
ESP8266_TX->D0
|
||||
ESP8266_RX->D1
|
||||
ESP8266_CH_PD->3.3V
|
||||
ESP8266_VCC->3.3V
|
||||
ESP8266_GND->GND
|
||||
|
||||
FTDI_RX->D3 //The baud rate of software serial can't be higher that 19200, so we use software serial as a debug port
|
||||
FTDI_TX->D2
|
||||
|
||||
When you use it with MEGA board, the connection should be like these:
|
||||
ESP8266_TX->RX1(D19)
|
||||
ESP8266_RX->TX1(D18)
|
||||
ESP8266_CH_PD->3.3V
|
||||
ESP8266_VCC->3.3V
|
||||
ESP8266_GND->GND
|
||||
|
||||
When you want to output the debug information, please use DebugSerial. For example,
|
||||
|
||||
DebugSerial.println("hello");
|
||||
|
||||
|
||||
Note: The size of message from ESP8266 is too big for arduino sometimes, so the library can't receive the whole buffer because
|
||||
the size of the hardware serial buffer which is defined in HardwareSerial.h is too small.
|
||||
|
||||
Open the file from \arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.h.
|
||||
See the follow line in the HardwareSerial.h file.
|
||||
|
||||
#define SERIAL_BUFFER_SIZE 64
|
||||
|
||||
The default size of the buffer is 64. Change it into a bigger number, like 256 or more.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#define SSID "Itead_1(Public)"
|
||||
#define PASSWORD "27955416"
|
||||
|
||||
|
||||
#include "uartWIFI.h"
|
||||
#include <SoftwareSerial.h>
|
||||
WIFI wifi;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
wifi.begin();
|
||||
bool b = wifi.Initialize(STA, SSID, PASSWORD);
|
||||
if(!b)
|
||||
{
|
||||
DebugSerial.println("Init error");
|
||||
}
|
||||
delay(8000); //make sure the module can have enough time to get an IP address
|
||||
String ipstring = wifi.showIP();
|
||||
DebugSerial.println("My IP address:");
|
||||
DebugSerial.println(ipstring); //show the ip address of module
|
||||
|
||||
String wifistring = wifi.showJAP();
|
||||
DebugSerial.println(wifistring); //show the name of current wifi access port
|
||||
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map uralWIFI
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
WIFI KEYWORD1
|
||||
DebugSerial KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
begin KEYWORD2
|
||||
Initialize KEYWORD2
|
||||
ipConfig KEYWORD2
|
||||
confMode KEYWORD2
|
||||
Reset KEYWORD2
|
||||
showAP KEYWORD2
|
||||
showJAP KEYWORD2
|
||||
confJAP KEYWORD2
|
||||
quitAP KEYWORD2
|
||||
showSAP KEYWORD2
|
||||
confSAP KEYWORD2
|
||||
showStatus KEYWORD2
|
||||
showMux KEYWORD2
|
||||
confMux KEYWORD2
|
||||
newMux KEYWORD2
|
||||
Send KEYWORD2
|
||||
closeMux KEYWORD2
|
||||
showIP KEYWORD2
|
||||
confServer KEYWORD2
|
||||
Initialize KEYWORD2
|
||||
ipConfig KEYWORD2
|
||||
ReceiveMessage KEYWORD2
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
OPEN LITERAL1
|
||||
WEP LITERAL1
|
||||
WAP_PSK LITERAL1
|
||||
WAP2_PSK LITERAL1
|
||||
WAP_WAP2_PSK LITERAL1
|
||||
TCP LITERAL1
|
||||
tcp LITERAL1
|
||||
UDP LITERAL1
|
||||
udp LITERAL1
|
||||
OPEN LITERAL1
|
||||
CLOSE LITERAL1
|
||||
STA LITERAL1
|
||||
AP LITERAL1
|
||||
AT+STA LITERAL1
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,122 @@
|
||||
|
||||
/*
|
||||
ESP8266 library
|
||||
|
||||
|
||||
Modified version
|
||||
V1.0 released the first version of ESP8266 library
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#ifndef __UARTWIFI_H__
|
||||
#define __UARTWIFI_H__
|
||||
#include <Arduino.h>
|
||||
//#include "NilRTOS.h"
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#define _DBG_RXPIN_ 9
|
||||
#define _DBG_TXPIN_ 10
|
||||
|
||||
#define debugBaudRate 9600
|
||||
|
||||
|
||||
//#define UNO //uncomment this line when you use it with UNO board
|
||||
#define MEGA //uncomment this line when you use it with MEGA board
|
||||
|
||||
|
||||
#define DEBUG
|
||||
|
||||
|
||||
#ifdef UNO
|
||||
#define _cell Serial
|
||||
#define DebugSerial mySerial
|
||||
|
||||
#endif
|
||||
#ifdef MEGA
|
||||
#define _cell Serial1
|
||||
#define DebugSerial Serial
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef UNO
|
||||
extern SoftwareSerial mySerial;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//The way of encrypstion
|
||||
#define OPEN 0
|
||||
#define WEP 1
|
||||
#define WAP_PSK 2
|
||||
#define WAP2_PSK 3
|
||||
#define WAP_WAP2_PSK 4
|
||||
|
||||
//Communication mode
|
||||
#define TCP 1
|
||||
#define tcp 1
|
||||
#define UDP 0
|
||||
#define udp 0
|
||||
|
||||
#define OPEN 1
|
||||
#define CLOSE 0
|
||||
|
||||
//The type of initialized WIFI
|
||||
#define STA 1
|
||||
#define AP 2
|
||||
#define AP_STA 3
|
||||
|
||||
#define SERIAL_TX_BUFFER_SIZE 128
|
||||
#define SERIAL_RX_BUFFER_SIZE 128
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class WIFI
|
||||
{
|
||||
public:
|
||||
|
||||
bool begin(void);
|
||||
|
||||
//Initialize port
|
||||
bool Initialize(byte mode, String ssid, String pwd, byte chl = 1, byte ecn = 2);
|
||||
boolean ipConfig(byte type, String addr, int port, boolean a = 0, byte id = 0);
|
||||
|
||||
boolean Send(String str); //send data in sigle connection mode
|
||||
boolean Send(byte id, String str); //send data int multiple connection mode
|
||||
|
||||
int ReceiveMessage(char *buf);
|
||||
|
||||
//String begin(void);
|
||||
/*=================WIFI Function Command=================*/
|
||||
void Reset(void); //reset the module
|
||||
bool confMode(byte a); //set the working mode of module
|
||||
boolean confJAP(String ssid , String pwd); //set the name and password of wifi
|
||||
boolean confSAP(String ssid , String pwd , byte chl , byte ecn); //set the parametter of SSID, password, channel, encryption in AP mode.
|
||||
|
||||
String showMode(void); //inquire the current mode of wifi module
|
||||
String showAP(void); //show the list of wifi hotspot
|
||||
String showJAP(void); //show the name of current wifi access port
|
||||
boolean quitAP(void); //quit the connection of current wifi
|
||||
String showSAP(void); //show the parameter of ssid, password, channel, encryption in AP mode
|
||||
|
||||
/*================TCP/IP commands================*/
|
||||
String showStatus(void); //inquire the connection status
|
||||
String showMux(void); //show the current connection mode(sigle or multiple)
|
||||
boolean confMux(boolean a); //set the connection mode(sigle:0 or multiple:1)
|
||||
boolean newMux(byte type, String addr, int port); //create new tcp or udp connection (sigle connection mode)
|
||||
boolean newMux(byte id, byte type, String addr, int port); //create new tcp or udp connection (multiple connection mode)(id:0-4)
|
||||
void closeMux(void); //close tcp or udp (sigle connection mode)
|
||||
void closeMux(byte id); //close tcp or udp (multiple connection mode)
|
||||
String showIP(void); //show the current ip address
|
||||
boolean confServer(byte mode, int port); //set the parameter of server
|
||||
|
||||
String m_rev;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,293 @@
|
||||
/*
|
||||
||
|
||||
|| @file Keypad.cpp
|
||||
|| @version 3.1
|
||||
|| @author Mark Stanley, Alexander Brevig
|
||||
|| @contact mstanley@technologist.com, alexanderbrevig@gmail.com
|
||||
||
|
||||
|| @description
|
||||
|| | This library provides a simple interface for using matrix
|
||||
|| | keypads. It supports multiple keypresses while maintaining
|
||||
|| | backwards compatibility with the old single key library.
|
||||
|| | It also supports user selectable pins and definable keymaps.
|
||||
|| #
|
||||
||
|
||||
|| @license
|
||||
|| | 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; version
|
||||
|| | 2.1 of the License.
|
||||
|| |
|
||||
|| | This library is distributed in the hope that it will be useful,
|
||||
|| | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|| | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
|| | Lesser General Public License for more details.
|
||||
|| |
|
||||
|| | You should have received a copy of the GNU Lesser General Public
|
||||
|| | License along with this library; if not, write to the Free Software
|
||||
|| | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|| #
|
||||
||
|
||||
*/
|
||||
#include <Keypad.h>
|
||||
|
||||
// <<constructor>> Allows custom keymap, pin configuration, and keypad sizes.
|
||||
Keypad::Keypad(char *userKeymap, byte *row, byte *col, byte numRows, byte numCols) {
|
||||
rowPins = row;
|
||||
columnPins = col;
|
||||
sizeKpd.rows = numRows;
|
||||
sizeKpd.columns = numCols;
|
||||
|
||||
begin(userKeymap);
|
||||
|
||||
setDebounceTime(10);
|
||||
setHoldTime(500);
|
||||
keypadEventListener = 0;
|
||||
|
||||
startTime = 0;
|
||||
single_key = false;
|
||||
}
|
||||
|
||||
// Let the user define a keymap - assume the same row/column count as defined in constructor
|
||||
void Keypad::begin(char *userKeymap) {
|
||||
keymap = userKeymap;
|
||||
}
|
||||
|
||||
// Returns a single key only. Retained for backwards compatibility.
|
||||
char Keypad::getKey() {
|
||||
single_key = true;
|
||||
|
||||
if (getKeys() && key[0].stateChanged && (key[0].kstate==PRESSED))
|
||||
return key[0].kchar;
|
||||
|
||||
single_key = false;
|
||||
|
||||
return NO_KEY;
|
||||
}
|
||||
|
||||
// Populate the key list.
|
||||
bool Keypad::getKeys() {
|
||||
bool keyActivity = false;
|
||||
|
||||
// Limit how often the keypad is scanned. This makes the loop() run 10 times as fast.
|
||||
if ( (millis()-startTime)>debounceTime ) {
|
||||
scanKeys();
|
||||
keyActivity = updateList();
|
||||
startTime = millis();
|
||||
}
|
||||
|
||||
return keyActivity;
|
||||
}
|
||||
|
||||
// Private : Hardware scan
|
||||
void Keypad::scanKeys() {
|
||||
// Re-intialize the row pins. Allows sharing these pins with other hardware.
|
||||
for (byte r=0; r<sizeKpd.rows; r++) {
|
||||
pin_mode(rowPins[r],INPUT_PULLUP);
|
||||
}
|
||||
|
||||
// bitMap stores ALL the keys that are being pressed.
|
||||
for (byte c=0; c<sizeKpd.columns; c++) {
|
||||
pin_mode(columnPins[c],OUTPUT);
|
||||
pin_write(columnPins[c], LOW); // Begin column pulse output.
|
||||
for (byte r=0; r<sizeKpd.rows; r++) {
|
||||
bitWrite(bitMap[r], c, !pin_read(rowPins[r])); // keypress is active low so invert to high.
|
||||
}
|
||||
// Set pin to high impedance input. Effectively ends column pulse.
|
||||
pin_write(columnPins[c],HIGH);
|
||||
pin_mode(columnPins[c],INPUT);
|
||||
}
|
||||
}
|
||||
|
||||
// Manage the list without rearranging the keys. Returns true if any keys on the list changed state.
|
||||
bool Keypad::updateList() {
|
||||
|
||||
bool anyActivity = false;
|
||||
|
||||
// Delete any IDLE keys
|
||||
for (byte i=0; i<LIST_MAX; i++) {
|
||||
if (key[i].kstate==IDLE) {
|
||||
key[i].kchar = NO_KEY;
|
||||
key[i].kcode = -1;
|
||||
key[i].stateChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Add new keys to empty slots in the key list.
|
||||
for (byte r=0; r<sizeKpd.rows; r++) {
|
||||
for (byte c=0; c<sizeKpd.columns; c++) {
|
||||
boolean button = bitRead(bitMap[r],c);
|
||||
char keyChar = keymap[r * sizeKpd.columns + c];
|
||||
int keyCode = r * sizeKpd.columns + c;
|
||||
int idx = findInList (keyCode);
|
||||
// Key is already on the list so set its next state.
|
||||
if (idx > -1) {
|
||||
nextKeyState(idx, button);
|
||||
}
|
||||
// Key is NOT on the list so add it.
|
||||
if ((idx == -1) && button) {
|
||||
for (byte i=0; i<LIST_MAX; i++) {
|
||||
if (key[i].kchar==NO_KEY) { // Find an empty slot or don't add key to list.
|
||||
key[i].kchar = keyChar;
|
||||
key[i].kcode = keyCode;
|
||||
key[i].kstate = IDLE; // Keys NOT on the list have an initial state of IDLE.
|
||||
nextKeyState (i, button);
|
||||
break; // Don't fill all the empty slots with the same key.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Report if the user changed the state of any key.
|
||||
for (byte i=0; i<LIST_MAX; i++) {
|
||||
if (key[i].stateChanged) anyActivity = true;
|
||||
}
|
||||
|
||||
return anyActivity;
|
||||
}
|
||||
|
||||
// Private
|
||||
// This function is a state machine but is also used for debouncing the keys.
|
||||
void Keypad::nextKeyState(byte idx, boolean button) {
|
||||
key[idx].stateChanged = false;
|
||||
|
||||
switch (key[idx].kstate) {
|
||||
case IDLE:
|
||||
if (button==CLOSED) {
|
||||
transitionTo (idx, PRESSED);
|
||||
holdTimer = millis(); } // Get ready for next HOLD state.
|
||||
break;
|
||||
case PRESSED:
|
||||
if ((millis()-holdTimer)>holdTime) // Waiting for a key HOLD...
|
||||
transitionTo (idx, HOLD);
|
||||
else if (button==OPEN) // or for a key to be RELEASED.
|
||||
transitionTo (idx, RELEASED);
|
||||
break;
|
||||
case HOLD:
|
||||
if (button==OPEN)
|
||||
transitionTo (idx, RELEASED);
|
||||
break;
|
||||
case RELEASED:
|
||||
transitionTo (idx, IDLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// New in 2.1
|
||||
bool Keypad::isPressed(char keyChar) {
|
||||
for (byte i=0; i<LIST_MAX; i++) {
|
||||
if ( key[i].kchar == keyChar ) {
|
||||
if ( (key[i].kstate == PRESSED) && key[i].stateChanged )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false; // Not pressed.
|
||||
}
|
||||
|
||||
// Search by character for a key in the list of active keys.
|
||||
// Returns -1 if not found or the index into the list of active keys.
|
||||
int Keypad::findInList (char keyChar) {
|
||||
for (byte i=0; i<LIST_MAX; i++) {
|
||||
if (key[i].kchar == keyChar) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Search by code for a key in the list of active keys.
|
||||
// Returns -1 if not found or the index into the list of active keys.
|
||||
int Keypad::findInList (int keyCode) {
|
||||
for (byte i=0; i<LIST_MAX; i++) {
|
||||
if (key[i].kcode == keyCode) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// New in 2.0
|
||||
char Keypad::waitForKey() {
|
||||
char waitKey = NO_KEY;
|
||||
while( (waitKey = getKey()) == NO_KEY ); // Block everything while waiting for a keypress.
|
||||
return waitKey;
|
||||
}
|
||||
|
||||
// Backwards compatibility function.
|
||||
KeyState Keypad::getState() {
|
||||
return key[0].kstate;
|
||||
}
|
||||
|
||||
// The end user can test for any changes in state before deciding
|
||||
// if any variables, etc. needs to be updated in their code.
|
||||
bool Keypad::keyStateChanged() {
|
||||
return key[0].stateChanged;
|
||||
}
|
||||
|
||||
// The number of keys on the key list, key[LIST_MAX], equals the number
|
||||
// of bytes in the key list divided by the number of bytes in a Key object.
|
||||
byte Keypad::numKeys() {
|
||||
return sizeof(key)/sizeof(Key);
|
||||
}
|
||||
|
||||
// Minimum debounceTime is 1 mS. Any lower *will* slow down the loop().
|
||||
void Keypad::setDebounceTime(uint debounce) {
|
||||
debounce<1 ? debounceTime=1 : debounceTime=debounce;
|
||||
}
|
||||
|
||||
void Keypad::setHoldTime(uint hold) {
|
||||
holdTime = hold;
|
||||
}
|
||||
|
||||
void Keypad::addEventListener(void (*listener)(char)){
|
||||
keypadEventListener = listener;
|
||||
}
|
||||
|
||||
void Keypad::transitionTo(byte idx, KeyState nextState) {
|
||||
key[idx].kstate = nextState;
|
||||
key[idx].stateChanged = true;
|
||||
|
||||
// Sketch used the getKey() function.
|
||||
// Calls keypadEventListener only when the first key in slot 0 changes state.
|
||||
if (single_key) {
|
||||
if ( (keypadEventListener!=NULL) && (idx==0) ) {
|
||||
keypadEventListener(key[0].kchar);
|
||||
}
|
||||
}
|
||||
// Sketch used the getKeys() function.
|
||||
// Calls keypadEventListener on any key that changes state.
|
||||
else {
|
||||
if (keypadEventListener!=NULL) {
|
||||
keypadEventListener(key[idx].kchar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|| @changelog
|
||||
|| | 3.1 2013-01-15 - Mark Stanley : Fixed missing RELEASED & IDLE status when using a single key.
|
||||
|| | 3.0 2012-07-12 - Mark Stanley : Made library multi-keypress by default. (Backwards compatible)
|
||||
|| | 3.0 2012-07-12 - Mark Stanley : Modified pin functions to support Keypad_I2C
|
||||
|| | 3.0 2012-07-12 - Stanley & Young : Removed static variables. Fix for multiple keypad objects.
|
||||
|| | 3.0 2012-07-12 - Mark Stanley : Fixed bug that caused shorted pins when pressing multiple keys.
|
||||
|| | 2.0 2011-12-29 - Mark Stanley : Added waitForKey().
|
||||
|| | 2.0 2011-12-23 - Mark Stanley : Added the public function keyStateChanged().
|
||||
|| | 2.0 2011-12-23 - Mark Stanley : Added the private function scanKeys().
|
||||
|| | 2.0 2011-12-23 - Mark Stanley : Moved the Finite State Machine into the function getKeyState().
|
||||
|| | 2.0 2011-12-23 - Mark Stanley : Removed the member variable lastUdate. Not needed after rewrite.
|
||||
|| | 1.8 2011-11-21 - Mark Stanley : Added decision logic to compile WProgram.h or Arduino.h
|
||||
|| | 1.8 2009-07-08 - Alexander Brevig : No longer uses arrays
|
||||
|| | 1.7 2009-06-18 - Alexander Brevig : Every time a state changes the keypadEventListener will trigger, if set.
|
||||
|| | 1.7 2009-06-18 - Alexander Brevig : Added setDebounceTime. setHoldTime specifies the amount of
|
||||
|| | microseconds before a HOLD state triggers
|
||||
|| | 1.7 2009-06-18 - Alexander Brevig : Added transitionTo
|
||||
|| | 1.6 2009-06-15 - Alexander Brevig : Added getState() and state variable
|
||||
|| | 1.5 2009-05-19 - Alexander Brevig : Added setHoldTime()
|
||||
|| | 1.4 2009-05-15 - Alexander Brevig : Added addEventListener
|
||||
|| | 1.3 2009-05-12 - Alexander Brevig : Added lastUdate, in order to do simple debouncing
|
||||
|| | 1.2 2009-05-09 - Alexander Brevig : Changed getKey()
|
||||
|| | 1.1 2009-04-28 - Alexander Brevig : Modified API, and made variables private
|
||||
|| | 1.0 2007-XX-XX - Mark Stanley : Initial Release
|
||||
|| #
|
||||
*/
|
||||
@ -0,0 +1,156 @@
|
||||
/*
|
||||
||
|
||||
|| @file Keypad.h
|
||||
|| @version 3.1
|
||||
|| @author Mark Stanley, Alexander Brevig
|
||||
|| @contact mstanley@technologist.com, alexanderbrevig@gmail.com
|
||||
||
|
||||
|| @description
|
||||
|| | This library provides a simple interface for using matrix
|
||||
|| | keypads. It supports multiple keypresses while maintaining
|
||||
|| | backwards compatibility with the old single key library.
|
||||
|| | It also supports user selectable pins and definable keymaps.
|
||||
|| #
|
||||
||
|
||||
|| @license
|
||||
|| | 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; version
|
||||
|| | 2.1 of the License.
|
||||
|| |
|
||||
|| | This library is distributed in the hope that it will be useful,
|
||||
|| | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|| | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
|| | Lesser General Public License for more details.
|
||||
|| |
|
||||
|| | You should have received a copy of the GNU Lesser General Public
|
||||
|| | License along with this library; if not, write to the Free Software
|
||||
|| | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|| #
|
||||
||
|
||||
*/
|
||||
|
||||
#ifndef KEYPAD_H
|
||||
#define KEYPAD_H
|
||||
|
||||
#include "utility/Key.h"
|
||||
|
||||
// Arduino versioning.
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
// bperrybap - Thanks for a well reasoned argument and the following macro(s).
|
||||
// See http://arduino.cc/forum/index.php/topic,142041.msg1069480.html#msg1069480
|
||||
#ifndef INPUT_PULLUP
|
||||
#warning "Using pinMode() INPUT_PULLUP AVR emulation"
|
||||
#define INPUT_PULLUP 0x2
|
||||
#define pinMode(_pin, _mode) _mypinMode(_pin, _mode)
|
||||
#define _mypinMode(_pin, _mode) \
|
||||
do { \
|
||||
if(_mode == INPUT_PULLUP) \
|
||||
pinMode(_pin, INPUT); \
|
||||
digitalWrite(_pin, 1); \
|
||||
if(_mode != INPUT_PULLUP) \
|
||||
pinMode(_pin, _mode); \
|
||||
}while(0)
|
||||
#endif
|
||||
|
||||
|
||||
#define OPEN LOW
|
||||
#define CLOSED HIGH
|
||||
|
||||
typedef char KeypadEvent;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long ulong;
|
||||
|
||||
// Made changes according to this post http://arduino.cc/forum/index.php?topic=58337.0
|
||||
// by Nick Gammon. Thanks for the input Nick. It actually saved 78 bytes for me. :)
|
||||
typedef struct {
|
||||
byte rows;
|
||||
byte columns;
|
||||
} KeypadSize;
|
||||
|
||||
#define LIST_MAX 10 // Max number of keys on the active list.
|
||||
#define MAPSIZE 10 // MAPSIZE is the number of rows (times 16 columns)
|
||||
#define makeKeymap(x) ((char*)x)
|
||||
|
||||
|
||||
//class Keypad : public Key, public HAL_obj {
|
||||
class Keypad : public Key {
|
||||
public:
|
||||
|
||||
Keypad(char *userKeymap, byte *row, byte *col, byte numRows, byte numCols);
|
||||
|
||||
virtual void pin_mode(byte pinNum, byte mode) { pinMode(pinNum, mode); }
|
||||
virtual void pin_write(byte pinNum, boolean level) { digitalWrite(pinNum, level); }
|
||||
virtual int pin_read(byte pinNum) { return digitalRead(pinNum); }
|
||||
|
||||
uint bitMap[MAPSIZE]; // 10 row x 16 column array of bits. Except Due which has 32 columns.
|
||||
Key key[LIST_MAX];
|
||||
unsigned long holdTimer;
|
||||
|
||||
char getKey();
|
||||
bool getKeys();
|
||||
KeyState getState();
|
||||
void begin(char *userKeymap);
|
||||
bool isPressed(char keyChar);
|
||||
void setDebounceTime(uint);
|
||||
void setHoldTime(uint);
|
||||
void addEventListener(void (*listener)(char));
|
||||
int findInList(char keyChar);
|
||||
int findInList(int keyCode);
|
||||
char waitForKey();
|
||||
bool keyStateChanged();
|
||||
byte numKeys();
|
||||
|
||||
private:
|
||||
unsigned long startTime;
|
||||
char *keymap;
|
||||
byte *rowPins;
|
||||
byte *columnPins;
|
||||
KeypadSize sizeKpd;
|
||||
uint debounceTime;
|
||||
uint holdTime;
|
||||
bool single_key;
|
||||
|
||||
void scanKeys();
|
||||
bool updateList();
|
||||
void nextKeyState(byte n, boolean button);
|
||||
void transitionTo(byte n, KeyState nextState);
|
||||
void (*keypadEventListener)(char);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
|| @changelog
|
||||
|| | 3.1 2013-01-15 - Mark Stanley : Fixed missing RELEASED & IDLE status when using a single key.
|
||||
|| | 3.0 2012-07-12 - Mark Stanley : Made library multi-keypress by default. (Backwards compatible)
|
||||
|| | 3.0 2012-07-12 - Mark Stanley : Modified pin functions to support Keypad_I2C
|
||||
|| | 3.0 2012-07-12 - Stanley & Young : Removed static variables. Fix for multiple keypad objects.
|
||||
|| | 3.0 2012-07-12 - Mark Stanley : Fixed bug that caused shorted pins when pressing multiple keys.
|
||||
|| | 2.0 2011-12-29 - Mark Stanley : Added waitForKey().
|
||||
|| | 2.0 2011-12-23 - Mark Stanley : Added the public function keyStateChanged().
|
||||
|| | 2.0 2011-12-23 - Mark Stanley : Added the private function scanKeys().
|
||||
|| | 2.0 2011-12-23 - Mark Stanley : Moved the Finite State Machine into the function getKeyState().
|
||||
|| | 2.0 2011-12-23 - Mark Stanley : Removed the member variable lastUdate. Not needed after rewrite.
|
||||
|| | 1.8 2011-11-21 - Mark Stanley : Added test to determine which header file to compile,
|
||||
|| | WProgram.h or Arduino.h.
|
||||
|| | 1.8 2009-07-08 - Alexander Brevig : No longer uses arrays
|
||||
|| | 1.7 2009-06-18 - Alexander Brevig : This library is a Finite State Machine every time a state changes
|
||||
|| | the keypadEventListener will trigger, if set
|
||||
|| | 1.7 2009-06-18 - Alexander Brevig : Added setDebounceTime setHoldTime specifies the amount of
|
||||
|| | microseconds before a HOLD state triggers
|
||||
|| | 1.7 2009-06-18 - Alexander Brevig : Added transitionTo
|
||||
|| | 1.6 2009-06-15 - Alexander Brevig : Added getState() and state variable
|
||||
|| | 1.5 2009-05-19 - Alexander Brevig : Added setHoldTime()
|
||||
|| | 1.4 2009-05-15 - Alexander Brevig : Added addEventListener
|
||||
|| | 1.3 2009-05-12 - Alexander Brevig : Added lastUdate, in order to do simple debouncing
|
||||
|| | 1.2 2009-05-09 - Alexander Brevig : Changed getKey()
|
||||
|| | 1.1 2009-04-28 - Alexander Brevig : Modified API, and made variables private
|
||||
|| | 1.0 2007-XX-XX - Mark Stanley : Initial Release
|
||||
|| #
|
||||
*/
|
||||
@ -0,0 +1,32 @@
|
||||
/*
|
||||
GIT: https://github.com/UCTRONICS/UCTRONICS_Arduino_kits
|
||||
Web: www.uctronics.com
|
||||
*/
|
||||
#include <Keypad.h>
|
||||
|
||||
const byte ROWS = 4; //four rows
|
||||
const byte COLS = 4; //four columns
|
||||
//define the cymbols on the buttons of the keypads
|
||||
char hexaKeys[ROWS][COLS] = {
|
||||
{'1','2','3','A'},
|
||||
{'4','5','6','B'},
|
||||
{'7','8','9','C'},
|
||||
{'*','0','#','D'}
|
||||
};
|
||||
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
|
||||
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
|
||||
|
||||
//initialize an instance of class NewKeypad
|
||||
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
char customKey = customKeypad.getKey();
|
||||
|
||||
if (customKey){
|
||||
Serial.println(customKey);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
# Keypad Library data types
|
||||
KeyState KEYWORD1
|
||||
Keypad KEYWORD1
|
||||
KeypadEvent KEYWORD1
|
||||
|
||||
# Keypad Library constants
|
||||
NO_KEY LITERAL1
|
||||
IDLE LITERAL1
|
||||
PRESSED LITERAL1
|
||||
HOLD LITERAL1
|
||||
RELEASED LITERAL1
|
||||
|
||||
# Keypad Library methods & functions
|
||||
addEventListener KEYWORD2
|
||||
bitMap KEYWORD2
|
||||
findKeyInList KEYWORD2
|
||||
getKey KEYWORD2
|
||||
getKeys KEYWORD2
|
||||
getState KEYWORD2
|
||||
holdTimer KEYWORD2
|
||||
isPressed KEYWORD2
|
||||
keyStateChanged KEYWORD2
|
||||
numKeys KEYWORD2
|
||||
pin_mode KEYWORD2
|
||||
pin_write KEYWORD2
|
||||
pin_read KEYWORD2
|
||||
setDebounceTime KEYWORD2
|
||||
setHoldTime KEYWORD2
|
||||
waitForKey KEYWORD2
|
||||
|
||||
# this is a macro that converts 2d arrays to pointers
|
||||
makeKeymap KEYWORD2
|
||||
|
||||
# List of objects created in the example sketches.
|
||||
kpd KEYWORD3
|
||||
keypad KEYWORD3
|
||||
kbrd KEYWORD3
|
||||
keyboard KEYWORD3
|
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
|| @file Key.cpp
|
||||
|| @version 1.0
|
||||
|| @author Mark Stanley
|
||||
|| @contact mstanley@technologist.com
|
||||
||
|
||||
|| @description
|
||||
|| | Key class provides an abstract definition of a key or button
|
||||
|| | and was initially designed to be used in conjunction with a
|
||||
|| | state-machine.
|
||||
|| #
|
||||
||
|
||||
|| @license
|
||||
|| | 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; version
|
||||
|| | 2.1 of the License.
|
||||
|| |
|
||||
|| | This library is distributed in the hope that it will be useful,
|
||||
|| | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|| | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
|| | Lesser General Public License for more details.
|
||||
|| |
|
||||
|| | You should have received a copy of the GNU Lesser General Public
|
||||
|| | License along with this library; if not, write to the Free Software
|
||||
|| | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|| #
|
||||
||
|
||||
*/
|
||||
#include <Key.h>
|
||||
|
||||
|
||||
// default constructor
|
||||
Key::Key() {
|
||||
kchar = NO_KEY;
|
||||
kstate = IDLE;
|
||||
stateChanged = false;
|
||||
}
|
||||
|
||||
// constructor
|
||||
Key::Key(char userKeyChar) {
|
||||
kchar = userKeyChar;
|
||||
kcode = -1;
|
||||
kstate = IDLE;
|
||||
stateChanged = false;
|
||||
}
|
||||
|
||||
|
||||
void Key::key_update (char userKeyChar, KeyState userState, boolean userStatus) {
|
||||
kchar = userKeyChar;
|
||||
kstate = userState;
|
||||
stateChanged = userStatus;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|| @changelog
|
||||
|| | 1.0 2012-06-04 - Mark Stanley : Initial Release
|
||||
|| #
|
||||
*/
|
||||
@ -0,0 +1,73 @@
|
||||
/*
|
||||
||
|
||||
|| @file Key.h
|
||||
|| @version 1.0
|
||||
|| @author Mark Stanley
|
||||
|| @contact mstanley@technologist.com
|
||||
||
|
||||
|| @description
|
||||
|| | Key class provides an abstract definition of a key or button
|
||||
|| | and was initially designed to be used in conjunction with a
|
||||
|| | state-machine.
|
||||
|| #
|
||||
||
|
||||
|| @license
|
||||
|| | 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; version
|
||||
|| | 2.1 of the License.
|
||||
|| |
|
||||
|| | This library is distributed in the hope that it will be useful,
|
||||
|| | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|| | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
|| | Lesser General Public License for more details.
|
||||
|| |
|
||||
|| | You should have received a copy of the GNU Lesser General Public
|
||||
|| | License along with this library; if not, write to the Free Software
|
||||
|| | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|| #
|
||||
||
|
||||
*/
|
||||
|
||||
#ifndef KEY_H
|
||||
#define KEY_H
|
||||
|
||||
// Arduino versioning.
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h" // for digitalRead, digitalWrite, etc
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#define OPEN LOW
|
||||
#define CLOSED HIGH
|
||||
|
||||
typedef unsigned int uint;
|
||||
typedef enum{ IDLE, PRESSED, HOLD, RELEASED } KeyState;
|
||||
|
||||
const char NO_KEY = '\0';
|
||||
|
||||
class Key {
|
||||
public:
|
||||
// members
|
||||
char kchar;
|
||||
int kcode;
|
||||
KeyState kstate;
|
||||
boolean stateChanged;
|
||||
|
||||
// methods
|
||||
Key();
|
||||
Key(char userKeyChar);
|
||||
void key_update(char userKeyChar, KeyState userState, boolean userStatus);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
|| @changelog
|
||||
|| | 1.0 2012-06-04 - Mark Stanley : Initial Release
|
||||
|| #
|
||||
*/
|
||||
@ -0,0 +1,213 @@
|
||||
/*
|
||||
* LedControl.cpp - A library for controling Leds with a MAX7219/MAX7221
|
||||
* Copyright (c) 2007 Eberhard Fahle
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* This permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include "LedControl.h"
|
||||
|
||||
//the opcodes for the MAX7221 and MAX7219
|
||||
#define OP_NOOP 0
|
||||
#define OP_DIGIT0 1
|
||||
#define OP_DIGIT1 2
|
||||
#define OP_DIGIT2 3
|
||||
#define OP_DIGIT3 4
|
||||
#define OP_DIGIT4 5
|
||||
#define OP_DIGIT5 6
|
||||
#define OP_DIGIT6 7
|
||||
#define OP_DIGIT7 8
|
||||
#define OP_DECODEMODE 9
|
||||
#define OP_INTENSITY 10
|
||||
#define OP_SCANLIMIT 11
|
||||
#define OP_SHUTDOWN 12
|
||||
#define OP_DISPLAYTEST 15
|
||||
|
||||
LedControl::LedControl(int dataPin, int clkPin, int csPin, int numDevices) {
|
||||
SPI_MOSI=dataPin;
|
||||
SPI_CLK=clkPin;
|
||||
SPI_CS=csPin;
|
||||
if(numDevices<=0 || numDevices>8 )
|
||||
numDevices=8;
|
||||
maxDevices=numDevices;
|
||||
pinMode(SPI_MOSI,OUTPUT);
|
||||
pinMode(SPI_CLK,OUTPUT);
|
||||
pinMode(SPI_CS,OUTPUT);
|
||||
digitalWrite(SPI_CS,HIGH);
|
||||
SPI_MOSI=dataPin;
|
||||
for(int i=0;i<64;i++)
|
||||
status[i]=0x00;
|
||||
for(int i=0;i<maxDevices;i++) {
|
||||
spiTransfer(i,OP_DISPLAYTEST,0);
|
||||
//scanlimit is set to max on startup
|
||||
setScanLimit(i,7);
|
||||
//decode is done in source
|
||||
spiTransfer(i,OP_DECODEMODE,0);
|
||||
clearDisplay(i);
|
||||
//we go into shutdown-mode on startup
|
||||
shutdown(i,true);
|
||||
}
|
||||
}
|
||||
|
||||
int LedControl::getDeviceCount() {
|
||||
return maxDevices;
|
||||
}
|
||||
|
||||
void LedControl::shutdown(int addr, bool b) {
|
||||
if(addr<0 || addr>=maxDevices)
|
||||
return;
|
||||
if(b)
|
||||
spiTransfer(addr, OP_SHUTDOWN,0);
|
||||
else
|
||||
spiTransfer(addr, OP_SHUTDOWN,1);
|
||||
}
|
||||
|
||||
void LedControl::setScanLimit(int addr, int limit) {
|
||||
if(addr<0 || addr>=maxDevices)
|
||||
return;
|
||||
if(limit>=0 || limit<8)
|
||||
spiTransfer(addr, OP_SCANLIMIT,limit);
|
||||
}
|
||||
|
||||
void LedControl::setIntensity(int addr, int intensity) {
|
||||
if(addr<0 || addr>=maxDevices)
|
||||
return;
|
||||
if(intensity>=0 || intensity<16)
|
||||
spiTransfer(addr, OP_INTENSITY,intensity);
|
||||
|
||||
}
|
||||
|
||||
void LedControl::clearDisplay(int addr) {
|
||||
int offset;
|
||||
|
||||
if(addr<0 || addr>=maxDevices)
|
||||
return;
|
||||
offset=addr*8;
|
||||
for(int i=0;i<8;i++) {
|
||||
status[offset+i]=0;
|
||||
spiTransfer(addr, i+1,status[offset+i]);
|
||||
}
|
||||
}
|
||||
|
||||
void LedControl::setLed(int addr, int row, int column, boolean state) {
|
||||
int offset;
|
||||
byte val=0x00;
|
||||
|
||||
if(addr<0 || addr>=maxDevices)
|
||||
return;
|
||||
if(row<0 || row>7 || column<0 || column>7)
|
||||
return;
|
||||
offset=addr*8;
|
||||
val=B10000000 >> column;
|
||||
if(state)
|
||||
status[offset+row]=status[offset+row]|val;
|
||||
else {
|
||||
val=~val;
|
||||
status[offset+row]=status[offset+row]&val;
|
||||
}
|
||||
spiTransfer(addr, row+1,status[offset+row]);
|
||||
}
|
||||
|
||||
void LedControl::setRow(int addr, int row, byte value) {
|
||||
int offset;
|
||||
if(addr<0 || addr>=maxDevices)
|
||||
return;
|
||||
if(row<0 || row>7)
|
||||
return;
|
||||
offset=addr*8;
|
||||
status[offset+row]=value;
|
||||
spiTransfer(addr, row+1,status[offset+row]);
|
||||
}
|
||||
|
||||
void LedControl::setColumn(int addr, int col, byte value) {
|
||||
byte val;
|
||||
|
||||
if(addr<0 || addr>=maxDevices)
|
||||
return;
|
||||
if(col<0 || col>7)
|
||||
return;
|
||||
for(int row=0;row<8;row++) {
|
||||
val=value >> (7-row);
|
||||
val=val & 0x01;
|
||||
setLed(addr,row,col,val);
|
||||
}
|
||||
}
|
||||
|
||||
void LedControl::setDigit(int addr, int digit, byte value, boolean dp) {
|
||||
int offset;
|
||||
byte v;
|
||||
|
||||
if(addr<0 || addr>=maxDevices)
|
||||
return;
|
||||
if(digit<0 || digit>7 || value>15)
|
||||
return;
|
||||
offset=addr*8;
|
||||
v=charTable[value];
|
||||
if(dp)
|
||||
v|=B10000000;
|
||||
status[offset+digit]=v;
|
||||
spiTransfer(addr, digit+1,v);
|
||||
|
||||
}
|
||||
|
||||
void LedControl::setChar(int addr, int digit, char value, boolean dp) {
|
||||
int offset;
|
||||
byte index,v;
|
||||
|
||||
if(addr<0 || addr>=maxDevices)
|
||||
return;
|
||||
if(digit<0 || digit>7)
|
||||
return;
|
||||
offset=addr*8;
|
||||
index=(byte)value;
|
||||
if(index >127) {
|
||||
//nothing define we use the space char
|
||||
value=32;
|
||||
}
|
||||
v=charTable[index];
|
||||
if(dp)
|
||||
v|=B10000000;
|
||||
status[offset+digit]=v;
|
||||
spiTransfer(addr, digit+1,v);
|
||||
}
|
||||
|
||||
void LedControl::spiTransfer(int addr, volatile byte opcode, volatile byte data) {
|
||||
//Create an array with the data to shift out
|
||||
int offset=addr*2;
|
||||
int maxbytes=maxDevices*2;
|
||||
|
||||
for(int i=0;i<maxbytes;i++)
|
||||
spidata[i]=(byte)0;
|
||||
//put our device data into the array
|
||||
spidata[offset+1]=opcode;
|
||||
spidata[offset]=data;
|
||||
//enable the line
|
||||
digitalWrite(SPI_CS,LOW);
|
||||
//Now shift out the data
|
||||
for(int i=maxbytes;i>0;i--)
|
||||
shiftOut(SPI_MOSI,SPI_CLK,MSBFIRST,spidata[i-1]);
|
||||
//latch the data onto the display
|
||||
digitalWrite(SPI_CS,HIGH);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,188 @@
|
||||
/*
|
||||
* LedControl.h - A library for controling Leds with a MAX7219/MAX7221
|
||||
* Copyright (c) 2007 Eberhard Fahle
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* This permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef LedControl_h
|
||||
#define LedControl_h
|
||||
|
||||
#if (ARDUINO >= 100)
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Segments to be switched on for characters and digits on
|
||||
* 7-Segment Displays
|
||||
*/
|
||||
const static byte charTable[128] = {
|
||||
B01111110,B00110000,B01101101,B01111001,B00110011,B01011011,B01011111,B01110000,
|
||||
B01111111,B01111011,B01110111,B00011111,B00001101,B00111101,B01001111,B01000111,
|
||||
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
|
||||
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
|
||||
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
|
||||
B00000000,B00000000,B00000000,B00000000,B10000000,B00000001,B10000000,B00000000,
|
||||
B01111110,B00110000,B01101101,B01111001,B00110011,B01011011,B01011111,B01110000,
|
||||
B01111111,B01111011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
|
||||
B00000000,B01110111,B00011111,B00001101,B00111101,B01001111,B01000111,B00000000,
|
||||
B00110111,B00000000,B00000000,B00000000,B00001110,B00000000,B00000000,B00000000,
|
||||
B01100111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
|
||||
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001000,
|
||||
B00000000,B01110111,B00011111,B00001101,B00111101,B01001111,B01000111,B00000000,
|
||||
B00110111,B00000000,B00000000,B00000000,B00001110,B00000000,B00000000,B00000000,
|
||||
B01100111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
|
||||
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000
|
||||
};
|
||||
|
||||
class LedControl {
|
||||
private :
|
||||
/* The array for shifting the data to the devices */
|
||||
byte spidata[16];
|
||||
/* Send out a single command to the device */
|
||||
void spiTransfer(int addr, byte opcode, byte data);
|
||||
|
||||
/* We keep track of the led-status for all 8 devices in this array */
|
||||
byte status[64];
|
||||
/* Data is shifted out of this pin*/
|
||||
int SPI_MOSI;
|
||||
/* The clock is signaled on this pin */
|
||||
int SPI_CLK;
|
||||
/* This one is driven LOW for chip selectzion */
|
||||
int SPI_CS;
|
||||
/* The maximum number of devices we use */
|
||||
int maxDevices;
|
||||
|
||||
public:
|
||||
/*
|
||||
* Create a new controler
|
||||
* Params :
|
||||
* dataPin pin on the Arduino where data gets shifted out
|
||||
* clockPin pin for the clock
|
||||
* csPin pin for selecting the device
|
||||
* numDevices maximum number of devices that can be controled
|
||||
*/
|
||||
LedControl(int dataPin, int clkPin, int csPin, int numDevices=1);
|
||||
|
||||
/*
|
||||
* Gets the number of devices attached to this LedControl.
|
||||
* Returns :
|
||||
* int the number of devices on this LedControl
|
||||
*/
|
||||
int getDeviceCount();
|
||||
|
||||
/*
|
||||
* Set the shutdown (power saving) mode for the device
|
||||
* Params :
|
||||
* addr The address of the display to control
|
||||
* status If true the device goes into power-down mode. Set to false
|
||||
* for normal operation.
|
||||
*/
|
||||
void shutdown(int addr, bool status);
|
||||
|
||||
/*
|
||||
* Set the number of digits (or rows) to be displayed.
|
||||
* See datasheet for sideeffects of the scanlimit on the brightness
|
||||
* of the display.
|
||||
* Params :
|
||||
* addr address of the display to control
|
||||
* limit number of digits to be displayed (1..8)
|
||||
*/
|
||||
void setScanLimit(int addr, int limit);
|
||||
|
||||
/*
|
||||
* Set the brightness of the display.
|
||||
* Params:
|
||||
* addr the address of the display to control
|
||||
* intensity the brightness of the display. (0..15)
|
||||
*/
|
||||
void setIntensity(int addr, int intensity);
|
||||
|
||||
/*
|
||||
* Switch all Leds on the display off.
|
||||
* Params:
|
||||
* addr address of the display to control
|
||||
*/
|
||||
void clearDisplay(int addr);
|
||||
|
||||
/*
|
||||
* Set the status of a single Led.
|
||||
* Params :
|
||||
* addr address of the display
|
||||
* row the row of the Led (0..7)
|
||||
* col the column of the Led (0..7)
|
||||
* state If true the led is switched on,
|
||||
* if false it is switched off
|
||||
*/
|
||||
void setLed(int addr, int row, int col, boolean state);
|
||||
|
||||
/*
|
||||
* Set all 8 Led's in a row to a new state
|
||||
* Params:
|
||||
* addr address of the display
|
||||
* row row which is to be set (0..7)
|
||||
* value each bit set to 1 will light up the
|
||||
* corresponding Led.
|
||||
*/
|
||||
void setRow(int addr, int row, byte value);
|
||||
|
||||
/*
|
||||
* Set all 8 Led's in a column to a new state
|
||||
* Params:
|
||||
* addr address of the display
|
||||
* col column which is to be set (0..7)
|
||||
* value each bit set to 1 will light up the
|
||||
* corresponding Led.
|
||||
*/
|
||||
void setColumn(int addr, int col, byte value);
|
||||
|
||||
/*
|
||||
* Display a hexadecimal digit on a 7-Segment Display
|
||||
* Params:
|
||||
* addr address of the display
|
||||
* digit the position of the digit on the display (0..7)
|
||||
* value the value to be displayed. (0x00..0x0F)
|
||||
* dp sets the decimal point.
|
||||
*/
|
||||
void setDigit(int addr, int digit, byte value, boolean dp);
|
||||
|
||||
/*
|
||||
* Display a character on a 7-Segment display.
|
||||
* There are only a few characters that make sense here :
|
||||
* '0','1','2','3','4','5','6','7','8','9','0',
|
||||
* 'A','b','c','d','E','F','H','L','P',
|
||||
* '.','-','_',' '
|
||||
* Params:
|
||||
* addr address of the display
|
||||
* digit the position of the character on the display (0..7)
|
||||
* value the character to be displayed.
|
||||
* dp sets the decimal point.
|
||||
*/
|
||||
void setChar(int addr, int digit, char value, boolean dp);
|
||||
};
|
||||
|
||||
#endif //LedControl.h
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,75 @@
|
||||
//GIT: https://github.com/UCTRONICS/UCTRONICS_Arduino_kits
|
||||
//Web: www.uctronics.com
|
||||
|
||||
#include "LedControl.h"
|
||||
|
||||
/*
|
||||
Now we need a LedControl to work with.
|
||||
***** These pin numbers will probably not work with your hardware *****
|
||||
pin 12 is connected to the DataIn
|
||||
pin 11 is connected to the CLK
|
||||
pin 10 is connected to LOAD
|
||||
We have only a single MAX72XX.
|
||||
*/
|
||||
LedControl lc=LedControl(12,11,10,1);
|
||||
|
||||
/* we always wait a bit between updates of the display */
|
||||
unsigned long delaytime=250;
|
||||
|
||||
void setup() {
|
||||
/*
|
||||
The MAX72XX is in power-saving mode on startup,
|
||||
we have to do a wakeup call
|
||||
*/
|
||||
lc.shutdown(0,false);
|
||||
/* Set the brightness to a medium values */
|
||||
lc.setIntensity(0,8);
|
||||
/* and clear the display */
|
||||
lc.clearDisplay(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
This method will display the characters for the
|
||||
word "Arduino" one after the other on digit 0.
|
||||
*/
|
||||
void writeArduinoOn7Segment() {
|
||||
lc.setChar(0,0,'a',false);
|
||||
delay(delaytime);
|
||||
lc.setRow(0,0,0x05);
|
||||
delay(delaytime);
|
||||
lc.setChar(0,0,'d',false);
|
||||
delay(delaytime);
|
||||
lc.setRow(0,0,0x1c);
|
||||
delay(delaytime);
|
||||
lc.setRow(0,0,B00010000);
|
||||
delay(delaytime);
|
||||
lc.setRow(0,0,0x15);
|
||||
delay(delaytime);
|
||||
lc.setRow(0,0,0x1D);
|
||||
delay(delaytime);
|
||||
lc.clearDisplay(0);
|
||||
delay(delaytime);
|
||||
}
|
||||
|
||||
/*
|
||||
This method will scroll all the hexa-decimal
|
||||
numbers and letters on the display. You will need at least
|
||||
four 7-Segment digits. otherwise it won't really look that good.
|
||||
*/
|
||||
void scrollDigits() {
|
||||
for(int i=0;i<13;i++) {
|
||||
lc.setDigit(0,3,i,false);
|
||||
lc.setDigit(0,2,i+1,false);
|
||||
lc.setDigit(0,1,i+2,false);
|
||||
lc.setDigit(0,0,i+3,false);
|
||||
delay(delaytime);
|
||||
}
|
||||
lc.clearDisplay(0);
|
||||
delay(delaytime);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
writeArduinoOn7Segment();
|
||||
scrollDigits();
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
//GIT: https://github.com/UCTRONICS/UCTRONICS_Arduino_kits
|
||||
//Web: www.uctronics.com
|
||||
#include "LedControl.h"
|
||||
|
||||
/*
|
||||
Now we need a LedControl to work with.
|
||||
***** These pin numbers will probably not work with your hardware *****
|
||||
pin 12 is connected to the DataIn
|
||||
pin 11 is connected to the CLK
|
||||
pin 10 is connected to LOAD
|
||||
***** Please set the number of devices you have *****
|
||||
But the maximum default of 8 MAX72XX wil also work.
|
||||
*/
|
||||
LedControl lc=LedControl(12,11,10,8);
|
||||
|
||||
/* we always wait a bit between updates of the display */
|
||||
unsigned long delaytime=500;
|
||||
|
||||
/*
|
||||
This time we have more than one device.
|
||||
But all of them have to be initialized
|
||||
individually.
|
||||
*/
|
||||
void setup() {
|
||||
//we have already set the number of devices when we created the LedControl
|
||||
int devices=lc.getDeviceCount();
|
||||
//we have to init all devices in a loop
|
||||
for(int address=0;address<devices;address++) {
|
||||
/*The MAX72XX is in power-saving mode on startup*/
|
||||
lc.shutdown(address,false);
|
||||
/* Set the brightness to a medium values */
|
||||
lc.setIntensity(address,8);
|
||||
/* and clear the display */
|
||||
lc.clearDisplay(address);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
//read the number cascaded devices
|
||||
int devices=lc.getDeviceCount();
|
||||
|
||||
//we have to init all devices in a loop
|
||||
for(int row=0;row<8;row++) {
|
||||
for(int col=0;col<8;col++) {
|
||||
for(int address=0;address<devices;address++) {
|
||||
delay(delaytime);
|
||||
lc.setLed(address,row,col,true);
|
||||
delay(delaytime);
|
||||
lc.setLed(address,row,col,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,164 @@
|
||||
//GIT: https://github.com/UCTRONICS/UCTRONICS_Arduino_kits
|
||||
//Web: www.uctronics.com
|
||||
#include "LedControl.h"
|
||||
|
||||
/*
|
||||
Now we need a LedControl to work with.
|
||||
***** These pin numbers will probably not work with your hardware *****
|
||||
pin 12 is connected to the DataIn
|
||||
pin 11 is connected to the CLK
|
||||
pin 10 is connected to LOAD
|
||||
We have only a single MAX72XX.
|
||||
*/
|
||||
LedControl lc=LedControl(12,11,10,1);
|
||||
|
||||
/* we always wait a bit between updates of the display */
|
||||
unsigned long delaytime=100;
|
||||
|
||||
void setup() {
|
||||
/*
|
||||
The MAX72XX is in power-saving mode on startup,
|
||||
we have to do a wakeup call
|
||||
*/
|
||||
lc.shutdown(0,false);
|
||||
/* Set the brightness to a medium values */
|
||||
lc.setIntensity(0,8);
|
||||
/* and clear the display */
|
||||
lc.clearDisplay(0);
|
||||
}
|
||||
|
||||
/*
|
||||
This method will display the characters for the
|
||||
word "Arduino" one after the other on the matrix.
|
||||
(you need at least 5x7 leds to see the whole chars)
|
||||
*/
|
||||
void writeArduinoOnMatrix() {
|
||||
/* here is the data for the characters */
|
||||
byte a[5]={B01111110,B10001000,B10001000,B10001000,B01111110};
|
||||
byte r[5]={B00111110,B00010000,B00100000,B00100000,B00010000};
|
||||
byte d[5]={B00011100,B00100010,B00100010,B00010010,B11111110};
|
||||
byte u[5]={B00111100,B00000010,B00000010,B00000100,B00111110};
|
||||
byte i[5]={B00000000,B00100010,B10111110,B00000010,B00000000};
|
||||
byte n[5]={B00111110,B00010000,B00100000,B00100000,B00011110};
|
||||
byte o[5]={B00011100,B00100010,B00100010,B00100010,B00011100};
|
||||
|
||||
/* now display them one by one with a small delay */
|
||||
lc.setRow(0,0,a[0]);
|
||||
lc.setRow(0,1,a[1]);
|
||||
lc.setRow(0,2,a[2]);
|
||||
lc.setRow(0,3,a[3]);
|
||||
lc.setRow(0,4,a[4]);
|
||||
delay(delaytime);
|
||||
lc.setRow(0,0,r[0]);
|
||||
lc.setRow(0,1,r[1]);
|
||||
lc.setRow(0,2,r[2]);
|
||||
lc.setRow(0,3,r[3]);
|
||||
lc.setRow(0,4,r[4]);
|
||||
delay(delaytime);
|
||||
lc.setRow(0,0,d[0]);
|
||||
lc.setRow(0,1,d[1]);
|
||||
lc.setRow(0,2,d[2]);
|
||||
lc.setRow(0,3,d[3]);
|
||||
lc.setRow(0,4,d[4]);
|
||||
delay(delaytime);
|
||||
lc.setRow(0,0,u[0]);
|
||||
lc.setRow(0,1,u[1]);
|
||||
lc.setRow(0,2,u[2]);
|
||||
lc.setRow(0,3,u[3]);
|
||||
lc.setRow(0,4,u[4]);
|
||||
delay(delaytime);
|
||||
lc.setRow(0,0,i[0]);
|
||||
lc.setRow(0,1,i[1]);
|
||||
lc.setRow(0,2,i[2]);
|
||||
lc.setRow(0,3,i[3]);
|
||||
lc.setRow(0,4,i[4]);
|
||||
delay(delaytime);
|
||||
lc.setRow(0,0,n[0]);
|
||||
lc.setRow(0,1,n[1]);
|
||||
lc.setRow(0,2,n[2]);
|
||||
lc.setRow(0,3,n[3]);
|
||||
lc.setRow(0,4,n[4]);
|
||||
delay(delaytime);
|
||||
lc.setRow(0,0,o[0]);
|
||||
lc.setRow(0,1,o[1]);
|
||||
lc.setRow(0,2,o[2]);
|
||||
lc.setRow(0,3,o[3]);
|
||||
lc.setRow(0,4,o[4]);
|
||||
delay(delaytime);
|
||||
lc.setRow(0,0,0);
|
||||
lc.setRow(0,1,0);
|
||||
lc.setRow(0,2,0);
|
||||
lc.setRow(0,3,0);
|
||||
lc.setRow(0,4,0);
|
||||
delay(delaytime);
|
||||
}
|
||||
|
||||
/*
|
||||
This function lights up a some Leds in a row.
|
||||
The pattern will be repeated on every row.
|
||||
The pattern will blink along with the row-number.
|
||||
row number 4 (index==3) will blink 4 times etc.
|
||||
*/
|
||||
void rows() {
|
||||
for(int row=0;row<8;row++) {
|
||||
delay(delaytime);
|
||||
lc.setRow(0,row,B10100000);
|
||||
delay(delaytime);
|
||||
lc.setRow(0,row,(byte)0);
|
||||
for(int i=0;i<row;i++) {
|
||||
delay(delaytime);
|
||||
lc.setRow(0,row,B10100000);
|
||||
delay(delaytime);
|
||||
lc.setRow(0,row,(byte)0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
This function lights up a some Leds in a column.
|
||||
The pattern will be repeated on every column.
|
||||
The pattern will blink along with the column-number.
|
||||
column number 4 (index==3) will blink 4 times etc.
|
||||
*/
|
||||
void columns() {
|
||||
for(int col=0;col<8;col++) {
|
||||
delay(delaytime);
|
||||
lc.setColumn(0,col,B10100000);
|
||||
delay(delaytime);
|
||||
lc.setColumn(0,col,(byte)0);
|
||||
for(int i=0;i<col;i++) {
|
||||
delay(delaytime);
|
||||
lc.setColumn(0,col,B10100000);
|
||||
delay(delaytime);
|
||||
lc.setColumn(0,col,(byte)0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
This function will light up every Led on the matrix.
|
||||
The led will blink along with the row-number.
|
||||
row number 4 (index==3) will blink 4 times etc.
|
||||
*/
|
||||
void single() {
|
||||
for(int row=0;row<8;row++) {
|
||||
for(int col=0;col<8;col++) {
|
||||
delay(delaytime);
|
||||
lc.setLed(0,row,col,true);
|
||||
delay(delaytime);
|
||||
for(int i=0;i<col;i++) {
|
||||
lc.setLed(0,row,col,false);
|
||||
delay(delaytime);
|
||||
lc.setLed(0,row,col,true);
|
||||
delay(delaytime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
writeArduinoOnMatrix();
|
||||
rows();
|
||||
columns();
|
||||
single();
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For LedControl
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
LedControl KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
shutdown KEYWORD2
|
||||
setScanLimit KEYWORD2
|
||||
setIntensity KEYWORD2
|
||||
clearDisplay KEYWORD2
|
||||
setLed KEYWORD2
|
||||
setRow KEYWORD2
|
||||
setColumn KEYWORD2
|
||||
setDigit KEYWORD2
|
||||
setChar KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
= Liquid Crystal Library for Arduino =
|
||||
|
||||
This library allows an Arduino board to control LiquidCrystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs.
|
||||
|
||||
For more information about this library please visit us at
|
||||
http://www.arduino.cc/en/Reference/LiquidCrystal
|
||||
|
||||
== License ==
|
||||
|
||||
Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved.
|
||||
Copyright (c) 2010 Arduino LLC. All right 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.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
@ -0,0 +1,63 @@
|
||||
/*
|
||||
GIT: https://github.com/UCTRONICS/UCTRONICS_Arduino_kits
|
||||
Web: www.uctronics.com
|
||||
LiquidCrystal Library - Autoscroll
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch demonstrates the use of the autoscroll()
|
||||
and noAutoscroll() functions to make new text scroll or not.
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
* LCD D4 pin to digital pin 5
|
||||
* LCD D5 pin to digital pin 4
|
||||
* LCD D6 pin to digital pin 3
|
||||
* LCD D7 pin to digital pin 2
|
||||
* LCD R/W pin to ground
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
*
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// set the cursor to (0,0):
|
||||
lcd.setCursor(0, 0);
|
||||
// print from 0 to 9:
|
||||
for (int thisChar = 0; thisChar < 10; thisChar++) {
|
||||
lcd.print(thisChar);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// set the cursor to (16,1):
|
||||
lcd.setCursor(16, 1);
|
||||
// set the display to automatically scroll:
|
||||
lcd.autoscroll();
|
||||
// print from 0 to 9:
|
||||
for (int thisChar = 0; thisChar < 10; thisChar++) {
|
||||
lcd.print(thisChar);
|
||||
delay(500);
|
||||
}
|
||||
// turn off automatic scrolling
|
||||
lcd.noAutoscroll();
|
||||
|
||||
// clear screen for the next loop:
|
||||
lcd.clear();
|
||||
}
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
/*
|
||||
GIT: https://github.com/UCTRONICS/UCTRONICS_Arduino_kits
|
||||
Web: www.uctronics.com
|
||||
LiquidCrystal Library - Blink
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch prints "Hello World!" to the LCD and makes the
|
||||
cursor block blink.
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
* LCD D4 pin to digital pin 5
|
||||
* LCD D5 pin to digital pin 4
|
||||
* LCD D6 pin to digital pin 3
|
||||
* LCD D7 pin to digital pin 2
|
||||
* LCD R/W pin to ground
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("hello, world!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Turn off the blinking cursor:
|
||||
lcd.noBlink();
|
||||
delay(3000);
|
||||
// Turn on the blinking cursor:
|
||||
lcd.blink();
|
||||
delay(3000);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
/*
|
||||
GIT: https://github.com/UCTRONICS/UCTRONICS_Arduino_kits
|
||||
Web: www.uctronics.com
|
||||
LiquidCrystal Library - Cursor
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch prints "Hello World!" to the LCD and
|
||||
uses the cursor() and noCursor() methods to turn
|
||||
on and off the cursor.
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
* LCD D4 pin to digital pin 5
|
||||
* LCD D5 pin to digital pin 4
|
||||
* LCD D6 pin to digital pin 3
|
||||
* LCD D7 pin to digital pin 2
|
||||
* LCD R/W pin to ground
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("hello, world!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Turn off the cursor:
|
||||
lcd.noCursor();
|
||||
delay(500);
|
||||
// Turn on the cursor:
|
||||
lcd.cursor();
|
||||
delay(500);
|
||||
}
|
||||
|
||||
@ -0,0 +1,140 @@
|
||||
/*
|
||||
LiquidCrystal Library - Custom Characters
|
||||
|
||||
Demonstrates how to add custom characters on an LCD display.
|
||||
The LiquidCrystal library works with all LCD displays that are
|
||||
compatible with the Hitachi HD44780 driver. There are many of
|
||||
them out there, and you can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch prints "I <heart> Arduino!" and a little dancing man
|
||||
to the LCD.
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
* LCD D4 pin to digital pin 5
|
||||
* LCD D5 pin to digital pin 4
|
||||
* LCD D6 pin to digital pin 3
|
||||
* LCD D7 pin to digital pin 2
|
||||
* LCD R/W pin to ground
|
||||
* 10K potentiometer:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
* 10K poterntiometer on pin A0
|
||||
|
||||
created 21 Mar 2011
|
||||
by Tom Igoe
|
||||
modified 11 Nov 2013
|
||||
by Scott Fitzgerald
|
||||
|
||||
Based on Adafruit's example at
|
||||
https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde
|
||||
|
||||
This example code is in the public domain.
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystal
|
||||
|
||||
Also useful:
|
||||
http://icontexto.com/charactercreator/
|
||||
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
// make some custom characters:
|
||||
byte heart[8] = {
|
||||
0b00000,
|
||||
0b01010,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b01110,
|
||||
0b00100,
|
||||
0b00000
|
||||
};
|
||||
|
||||
byte smiley[8] = {
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b01010,
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b10001,
|
||||
0b01110,
|
||||
0b00000
|
||||
};
|
||||
|
||||
byte frownie[8] = {
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b01010,
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b00000,
|
||||
0b01110,
|
||||
0b10001
|
||||
};
|
||||
|
||||
byte armsDown[8] = {
|
||||
0b00100,
|
||||
0b01010,
|
||||
0b00100,
|
||||
0b00100,
|
||||
0b01110,
|
||||
0b10101,
|
||||
0b00100,
|
||||
0b01010
|
||||
};
|
||||
|
||||
byte armsUp[8] = {
|
||||
0b00100,
|
||||
0b01010,
|
||||
0b00100,
|
||||
0b10101,
|
||||
0b01110,
|
||||
0b00100,
|
||||
0b00100,
|
||||
0b01010
|
||||
};
|
||||
|
||||
void setup() {
|
||||
// initialize LCD and set up the number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
|
||||
// create a new character
|
||||
lcd.createChar(0, heart);
|
||||
// create a new character
|
||||
lcd.createChar(1, smiley);
|
||||
// create a new character
|
||||
lcd.createChar(2, frownie);
|
||||
// create a new character
|
||||
lcd.createChar(3, armsDown);
|
||||
// create a new character
|
||||
lcd.createChar(4, armsUp);
|
||||
|
||||
// Print a message to the lcd.
|
||||
lcd.print("I ");
|
||||
lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte
|
||||
lcd.print(" Arduino! ");
|
||||
lcd.write((byte) 1);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the potentiometer on A0:
|
||||
int sensorReading = analogRead(A0);
|
||||
// map the result to 200 - 1000:
|
||||
int delayTime = map(sensorReading, 0, 1023, 200, 1000);
|
||||
// set the cursor to the bottom row, 5th position:
|
||||
lcd.setCursor(4, 1);
|
||||
// draw the little man, arms down:
|
||||
lcd.write(3);
|
||||
delay(delayTime);
|
||||
lcd.setCursor(4, 1);
|
||||
// draw him arms up:
|
||||
lcd.write(4);
|
||||
delay(delayTime);
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
LiquidCrystal Library - display() and noDisplay()
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch prints "Hello World!" to the LCD and uses the
|
||||
display() and noDisplay() functions to turn on and off
|
||||
the display.
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
* LCD D4 pin to digital pin 5
|
||||
* LCD D5 pin to digital pin 4
|
||||
* LCD D6 pin to digital pin 3
|
||||
* LCD D7 pin to digital pin 2
|
||||
* LCD R/W pin to ground
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystalDisplay
|
||||
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("hello, world!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Turn off the display:
|
||||
lcd.noDisplay();
|
||||
delay(500);
|
||||
// Turn on the display:
|
||||
lcd.display();
|
||||
delay(500);
|
||||
}
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
/*
|
||||
LiquidCrystal Library - Hello World
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch prints "Hello World!" to the LCD
|
||||
and shows the time.
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
* LCD D4 pin to digital pin 5
|
||||
* LCD D5 pin to digital pin 4
|
||||
* LCD D6 pin to digital pin 3
|
||||
* LCD D7 pin to digital pin 2
|
||||
* LCD R/W pin to ground
|
||||
* LCD VSS pin to ground
|
||||
* LCD VCC pin to 5V
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystal
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("hello, world!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// set the cursor to column 0, line 1
|
||||
// (note: line 1 is the second row, since counting begins with 0):
|
||||
lcd.setCursor(0, 1);
|
||||
// print the number of seconds since reset:
|
||||
lcd.print(millis() / 1000);
|
||||
}
|
||||
|
||||
@ -0,0 +1,86 @@
|
||||
/*
|
||||
LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight()
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch prints "Hello World!" to the LCD and uses the
|
||||
scrollDisplayLeft() and scrollDisplayRight() methods to scroll
|
||||
the text.
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
* LCD D4 pin to digital pin 5
|
||||
* LCD D5 pin to digital pin 4
|
||||
* LCD D6 pin to digital pin 3
|
||||
* LCD D7 pin to digital pin 2
|
||||
* LCD R/W pin to ground
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystalScroll
|
||||
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("hello, world!");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// scroll 13 positions (string length) to the left
|
||||
// to move it offscreen left:
|
||||
for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
|
||||
// scroll one position left:
|
||||
lcd.scrollDisplayLeft();
|
||||
// wait a bit:
|
||||
delay(150);
|
||||
}
|
||||
|
||||
// scroll 29 positions (string length + display length) to the right
|
||||
// to move it offscreen right:
|
||||
for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
|
||||
// scroll one position right:
|
||||
lcd.scrollDisplayRight();
|
||||
// wait a bit:
|
||||
delay(150);
|
||||
}
|
||||
|
||||
// scroll 16 positions (display length + string length) to the left
|
||||
// to move it back to center:
|
||||
for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
|
||||
// scroll one position left:
|
||||
lcd.scrollDisplayLeft();
|
||||
// wait a bit:
|
||||
delay(150);
|
||||
}
|
||||
|
||||
// delay at the end of the full loop:
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,64 @@
|
||||
/*
|
||||
LiquidCrystal Library - Serial Input
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch displays text sent over the serial port
|
||||
(e.g. from the Serial Monitor) on an attached LCD.
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
* LCD D4 pin to digital pin 5
|
||||
* LCD D5 pin to digital pin 4
|
||||
* LCD D6 pin to digital pin 3
|
||||
* LCD D7 pin to digital pin 2
|
||||
* LCD R/W pin to ground
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystalSerial
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// initialize the serial communications:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// when characters arrive over the serial port...
|
||||
if (Serial.available()) {
|
||||
// wait a bit for the entire message to arrive
|
||||
delay(100);
|
||||
// clear the screen
|
||||
lcd.clear();
|
||||
// read all the available characters
|
||||
while (Serial.available() > 0) {
|
||||
// display each character to the LCD
|
||||
lcd.write(Serial.read());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
/*
|
||||
LiquidCrystal Library - TextDirection
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch demonstrates how to use leftToRight() and rightToLeft()
|
||||
to move the cursor.
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
* LCD D4 pin to digital pin 5
|
||||
* LCD D5 pin to digital pin 4
|
||||
* LCD D6 pin to digital pin 3
|
||||
* LCD D7 pin to digital pin 2
|
||||
* LCD R/W pin to ground
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystalTextDirection
|
||||
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
int thisChar = 'a';
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// turn on the cursor:
|
||||
lcd.cursor();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// reverse directions at 'm':
|
||||
if (thisChar == 'm') {
|
||||
// go right for the next letter
|
||||
lcd.rightToLeft();
|
||||
}
|
||||
// reverse again at 's':
|
||||
if (thisChar == 's') {
|
||||
// go left for the next letter
|
||||
lcd.leftToRight();
|
||||
}
|
||||
// reset at 'z':
|
||||
if (thisChar > 'z') {
|
||||
// go to (0,0):
|
||||
lcd.home();
|
||||
// start again at 0
|
||||
thisChar = 'a';
|
||||
}
|
||||
// print the character
|
||||
lcd.write(thisChar);
|
||||
// wait a second:
|
||||
delay(1000);
|
||||
// increment the letter:
|
||||
thisChar++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,72 @@
|
||||
/*
|
||||
LiquidCrystal Library - setCursor
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch prints to all the positions of the LCD using the
|
||||
setCursor() method:
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
* LCD D4 pin to digital pin 5
|
||||
* LCD D5 pin to digital pin 4
|
||||
* LCD D6 pin to digital pin 3
|
||||
* LCD D7 pin to digital pin 2
|
||||
* LCD R/W pin to ground
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystalSetCursor
|
||||
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// these constants won't change. But you can change the size of
|
||||
// your LCD using them:
|
||||
const int numRows = 2;
|
||||
const int numCols = 16;
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(numCols, numRows);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// loop from ASCII 'a' to ASCII 'z':
|
||||
for (int thisLetter = 'a'; thisLetter <= 'z'; thisLetter++) {
|
||||
// loop over the columns:
|
||||
for (int thisRow = 0; thisRow < numRows; thisRow++) {
|
||||
// loop over the rows:
|
||||
for (int thisCol = 0; thisCol < numCols; thisCol++) {
|
||||
// set the cursor position:
|
||||
lcd.setCursor(thisCol, thisRow);
|
||||
// print the letter:
|
||||
lcd.write(thisLetter);
|
||||
delay(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,38 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For LiquidCrystal
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
LiquidCrystal KEYWORD1 LiquidCrystal
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
begin KEYWORD2
|
||||
clear KEYWORD2
|
||||
home KEYWORD2
|
||||
print KEYWORD2
|
||||
setCursor KEYWORD2
|
||||
cursor KEYWORD2
|
||||
noCursor KEYWORD2
|
||||
blink KEYWORD2
|
||||
noBlink KEYWORD2
|
||||
display KEYWORD2
|
||||
noDisplay KEYWORD2
|
||||
autoscroll KEYWORD2
|
||||
noAutoscroll KEYWORD2
|
||||
leftToRight KEYWORD2
|
||||
rightToLeft KEYWORD2
|
||||
scrollDisplayLeft KEYWORD2
|
||||
scrollDisplayRight KEYWORD2
|
||||
createChar KEYWORD2
|
||||
setRowOffsets KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
name=LiquidCrystal
|
||||
version=1.0.5
|
||||
author=Arduino, Adafruit
|
||||
maintainer=Arduino <info@arduino.cc>
|
||||
sentence=Allows communication with alphanumerical liquid crystal displays (LCDs).
|
||||
paragraph=This library allows an Arduino/Genuino board to control LiquidCrystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. The library works with in either 4 or 8 bit mode (i.e. using 4 or 8 data lines in addition to the rs, enable, and, optionally, the rw control lines).
|
||||
category=Display
|
||||
url=http://www.arduino.cc/en/Reference/LiquidCrystal
|
||||
architectures=*
|
||||
@ -0,0 +1,326 @@
|
||||
#include "LiquidCrystal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "Arduino.h"
|
||||
|
||||
// When the display powers up, it is configured as follows:
|
||||
//
|
||||
// 1. Display clear
|
||||
// 2. Function set:
|
||||
// DL = 1; 8-bit interface data
|
||||
// N = 0; 1-line display
|
||||
// F = 0; 5x8 dot character font
|
||||
// 3. Display on/off control:
|
||||
// D = 0; Display off
|
||||
// C = 0; Cursor off
|
||||
// B = 0; Blinking off
|
||||
// 4. Entry mode set:
|
||||
// I/D = 1; Increment by 1
|
||||
// S = 0; No shift
|
||||
//
|
||||
// Note, however, that resetting the Arduino doesn't reset the LCD, so we
|
||||
// can't assume that its in that state when a sketch starts (and the
|
||||
// LiquidCrystal constructor is called).
|
||||
|
||||
LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
|
||||
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
|
||||
{
|
||||
init(0, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7);
|
||||
}
|
||||
|
||||
LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
|
||||
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
|
||||
{
|
||||
init(0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7);
|
||||
}
|
||||
|
||||
LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3)
|
||||
{
|
||||
init(1, rs, rw, enable, d0, d1, d2, d3, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3)
|
||||
{
|
||||
init(1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
|
||||
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
|
||||
{
|
||||
_rs_pin = rs;
|
||||
_rw_pin = rw;
|
||||
_enable_pin = enable;
|
||||
|
||||
_data_pins[0] = d0;
|
||||
_data_pins[1] = d1;
|
||||
_data_pins[2] = d2;
|
||||
_data_pins[3] = d3;
|
||||
_data_pins[4] = d4;
|
||||
_data_pins[5] = d5;
|
||||
_data_pins[6] = d6;
|
||||
_data_pins[7] = d7;
|
||||
|
||||
if (fourbitmode)
|
||||
_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
|
||||
else
|
||||
_displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS;
|
||||
|
||||
begin(16, 1);
|
||||
}
|
||||
|
||||
void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
|
||||
if (lines > 1) {
|
||||
_displayfunction |= LCD_2LINE;
|
||||
}
|
||||
_numlines = lines;
|
||||
|
||||
setRowOffsets(0x00, 0x40, 0x00 + cols, 0x40 + cols);
|
||||
|
||||
// for some 1 line displays you can select a 10 pixel high font
|
||||
if ((dotsize != LCD_5x8DOTS) && (lines == 1)) {
|
||||
_displayfunction |= LCD_5x10DOTS;
|
||||
}
|
||||
|
||||
pinMode(_rs_pin, OUTPUT);
|
||||
// we can save 1 pin by not using RW. Indicate by passing 255 instead of pin#
|
||||
if (_rw_pin != 255) {
|
||||
pinMode(_rw_pin, OUTPUT);
|
||||
}
|
||||
pinMode(_enable_pin, OUTPUT);
|
||||
|
||||
// Do these once, instead of every time a character is drawn for speed reasons.
|
||||
for (int i=0; i<((_displayfunction & LCD_8BITMODE) ? 8 : 4); ++i)
|
||||
{
|
||||
pinMode(_data_pins[i], OUTPUT);
|
||||
}
|
||||
|
||||
// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
|
||||
// according to datasheet, we need at least 40ms after power rises above 2.7V
|
||||
// before sending commands. Arduino can turn on way before 4.5V so we'll wait 50
|
||||
delayMicroseconds(50000);
|
||||
// Now we pull both RS and R/W low to begin commands
|
||||
digitalWrite(_rs_pin, LOW);
|
||||
digitalWrite(_enable_pin, LOW);
|
||||
if (_rw_pin != 255) {
|
||||
digitalWrite(_rw_pin, LOW);
|
||||
}
|
||||
|
||||
//put the LCD into 4 bit or 8 bit mode
|
||||
if (! (_displayfunction & LCD_8BITMODE)) {
|
||||
// this is according to the hitachi HD44780 datasheet
|
||||
// figure 24, pg 46
|
||||
|
||||
// we start in 8bit mode, try to set 4 bit mode
|
||||
write4bits(0x03);
|
||||
delayMicroseconds(4500); // wait min 4.1ms
|
||||
|
||||
// second try
|
||||
write4bits(0x03);
|
||||
delayMicroseconds(4500); // wait min 4.1ms
|
||||
|
||||
// third go!
|
||||
write4bits(0x03);
|
||||
delayMicroseconds(150);
|
||||
|
||||
// finally, set to 4-bit interface
|
||||
write4bits(0x02);
|
||||
} else {
|
||||
// this is according to the hitachi HD44780 datasheet
|
||||
// page 45 figure 23
|
||||
|
||||
// Send function set command sequence
|
||||
command(LCD_FUNCTIONSET | _displayfunction);
|
||||
delayMicroseconds(4500); // wait more than 4.1ms
|
||||
|
||||
// second try
|
||||
command(LCD_FUNCTIONSET | _displayfunction);
|
||||
delayMicroseconds(150);
|
||||
|
||||
// third go
|
||||
command(LCD_FUNCTIONSET | _displayfunction);
|
||||
}
|
||||
|
||||
// finally, set # lines, font size, etc.
|
||||
command(LCD_FUNCTIONSET | _displayfunction);
|
||||
|
||||
// turn the display on with no cursor or blinking default
|
||||
_displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
|
||||
display();
|
||||
|
||||
// clear it off
|
||||
clear();
|
||||
|
||||
// Initialize to default text direction (for romance languages)
|
||||
_displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
|
||||
// set the entry mode
|
||||
command(LCD_ENTRYMODESET | _displaymode);
|
||||
|
||||
}
|
||||
|
||||
void LiquidCrystal::setRowOffsets(int row0, int row1, int row2, int row3)
|
||||
{
|
||||
_row_offsets[0] = row0;
|
||||
_row_offsets[1] = row1;
|
||||
_row_offsets[2] = row2;
|
||||
_row_offsets[3] = row3;
|
||||
}
|
||||
|
||||
/********** high level commands, for the user! */
|
||||
void LiquidCrystal::clear()
|
||||
{
|
||||
command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero
|
||||
delayMicroseconds(2000); // this command takes a long time!
|
||||
}
|
||||
|
||||
void LiquidCrystal::home()
|
||||
{
|
||||
command(LCD_RETURNHOME); // set cursor position to zero
|
||||
delayMicroseconds(2000); // this command takes a long time!
|
||||
}
|
||||
|
||||
void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
|
||||
{
|
||||
const size_t max_lines = sizeof(_row_offsets) / sizeof(*_row_offsets);
|
||||
if ( row >= max_lines ) {
|
||||
row = max_lines - 1; // we count rows starting w/0
|
||||
}
|
||||
if ( row >= _numlines ) {
|
||||
row = _numlines - 1; // we count rows starting w/0
|
||||
}
|
||||
|
||||
command(LCD_SETDDRAMADDR | (col + _row_offsets[row]));
|
||||
}
|
||||
|
||||
// Turn the display on/off (quickly)
|
||||
void LiquidCrystal::noDisplay() {
|
||||
_displaycontrol &= ~LCD_DISPLAYON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
void LiquidCrystal::display() {
|
||||
_displaycontrol |= LCD_DISPLAYON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
|
||||
// Turns the underline cursor on/off
|
||||
void LiquidCrystal::noCursor() {
|
||||
_displaycontrol &= ~LCD_CURSORON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
void LiquidCrystal::cursor() {
|
||||
_displaycontrol |= LCD_CURSORON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
|
||||
// Turn on and off the blinking cursor
|
||||
void LiquidCrystal::noBlink() {
|
||||
_displaycontrol &= ~LCD_BLINKON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
void LiquidCrystal::blink() {
|
||||
_displaycontrol |= LCD_BLINKON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
|
||||
// These commands scroll the display without changing the RAM
|
||||
void LiquidCrystal::scrollDisplayLeft(void) {
|
||||
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
|
||||
}
|
||||
void LiquidCrystal::scrollDisplayRight(void) {
|
||||
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
|
||||
}
|
||||
|
||||
// This is for text that flows Left to Right
|
||||
void LiquidCrystal::leftToRight(void) {
|
||||
_displaymode |= LCD_ENTRYLEFT;
|
||||
command(LCD_ENTRYMODESET | _displaymode);
|
||||
}
|
||||
|
||||
// This is for text that flows Right to Left
|
||||
void LiquidCrystal::rightToLeft(void) {
|
||||
_displaymode &= ~LCD_ENTRYLEFT;
|
||||
command(LCD_ENTRYMODESET | _displaymode);
|
||||
}
|
||||
|
||||
// This will 'right justify' text from the cursor
|
||||
void LiquidCrystal::autoscroll(void) {
|
||||
_displaymode |= LCD_ENTRYSHIFTINCREMENT;
|
||||
command(LCD_ENTRYMODESET | _displaymode);
|
||||
}
|
||||
|
||||
// This will 'left justify' text from the cursor
|
||||
void LiquidCrystal::noAutoscroll(void) {
|
||||
_displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
|
||||
command(LCD_ENTRYMODESET | _displaymode);
|
||||
}
|
||||
|
||||
// Allows us to fill the first 8 CGRAM locations
|
||||
// with custom characters
|
||||
void LiquidCrystal::createChar(uint8_t location, uint8_t charmap[]) {
|
||||
location &= 0x7; // we only have 8 locations 0-7
|
||||
command(LCD_SETCGRAMADDR | (location << 3));
|
||||
for (int i=0; i<8; i++) {
|
||||
write(charmap[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/*********** mid level commands, for sending data/cmds */
|
||||
|
||||
inline void LiquidCrystal::command(uint8_t value) {
|
||||
send(value, LOW);
|
||||
}
|
||||
|
||||
inline size_t LiquidCrystal::write(uint8_t value) {
|
||||
send(value, HIGH);
|
||||
return 1; // assume sucess
|
||||
}
|
||||
|
||||
/************ low level data pushing commands **********/
|
||||
|
||||
// write either command or data, with automatic 4/8-bit selection
|
||||
void LiquidCrystal::send(uint8_t value, uint8_t mode) {
|
||||
digitalWrite(_rs_pin, mode);
|
||||
|
||||
// if there is a RW pin indicated, set it low to Write
|
||||
if (_rw_pin != 255) {
|
||||
digitalWrite(_rw_pin, LOW);
|
||||
}
|
||||
|
||||
if (_displayfunction & LCD_8BITMODE) {
|
||||
write8bits(value);
|
||||
} else {
|
||||
write4bits(value>>4);
|
||||
write4bits(value);
|
||||
}
|
||||
}
|
||||
|
||||
void LiquidCrystal::pulseEnable(void) {
|
||||
digitalWrite(_enable_pin, LOW);
|
||||
delayMicroseconds(1);
|
||||
digitalWrite(_enable_pin, HIGH);
|
||||
delayMicroseconds(1); // enable pulse must be >450ns
|
||||
digitalWrite(_enable_pin, LOW);
|
||||
delayMicroseconds(100); // commands need > 37us to settle
|
||||
}
|
||||
|
||||
void LiquidCrystal::write4bits(uint8_t value) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
digitalWrite(_data_pins[i], (value >> i) & 0x01);
|
||||
}
|
||||
|
||||
pulseEnable();
|
||||
}
|
||||
|
||||
void LiquidCrystal::write8bits(uint8_t value) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
digitalWrite(_data_pins[i], (value >> i) & 0x01);
|
||||
}
|
||||
|
||||
pulseEnable();
|
||||
}
|
||||
@ -0,0 +1,108 @@
|
||||
#ifndef LiquidCrystal_h
|
||||
#define LiquidCrystal_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "Print.h"
|
||||
|
||||
// commands
|
||||
#define LCD_CLEARDISPLAY 0x01
|
||||
#define LCD_RETURNHOME 0x02
|
||||
#define LCD_ENTRYMODESET 0x04
|
||||
#define LCD_DISPLAYCONTROL 0x08
|
||||
#define LCD_CURSORSHIFT 0x10
|
||||
#define LCD_FUNCTIONSET 0x20
|
||||
#define LCD_SETCGRAMADDR 0x40
|
||||
#define LCD_SETDDRAMADDR 0x80
|
||||
|
||||
// flags for display entry mode
|
||||
#define LCD_ENTRYRIGHT 0x00
|
||||
#define LCD_ENTRYLEFT 0x02
|
||||
#define LCD_ENTRYSHIFTINCREMENT 0x01
|
||||
#define LCD_ENTRYSHIFTDECREMENT 0x00
|
||||
|
||||
// flags for display on/off control
|
||||
#define LCD_DISPLAYON 0x04
|
||||
#define LCD_DISPLAYOFF 0x00
|
||||
#define LCD_CURSORON 0x02
|
||||
#define LCD_CURSOROFF 0x00
|
||||
#define LCD_BLINKON 0x01
|
||||
#define LCD_BLINKOFF 0x00
|
||||
|
||||
// flags for display/cursor shift
|
||||
#define LCD_DISPLAYMOVE 0x08
|
||||
#define LCD_CURSORMOVE 0x00
|
||||
#define LCD_MOVERIGHT 0x04
|
||||
#define LCD_MOVELEFT 0x00
|
||||
|
||||
// flags for function set
|
||||
#define LCD_8BITMODE 0x10
|
||||
#define LCD_4BITMODE 0x00
|
||||
#define LCD_2LINE 0x08
|
||||
#define LCD_1LINE 0x00
|
||||
#define LCD_5x10DOTS 0x04
|
||||
#define LCD_5x8DOTS 0x00
|
||||
|
||||
class LiquidCrystal : public Print {
|
||||
public:
|
||||
LiquidCrystal(uint8_t rs, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
|
||||
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
|
||||
LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
|
||||
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
|
||||
LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
|
||||
LiquidCrystal(uint8_t rs, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
|
||||
|
||||
void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
|
||||
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
|
||||
|
||||
void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
|
||||
|
||||
void clear();
|
||||
void home();
|
||||
|
||||
void noDisplay();
|
||||
void display();
|
||||
void noBlink();
|
||||
void blink();
|
||||
void noCursor();
|
||||
void cursor();
|
||||
void scrollDisplayLeft();
|
||||
void scrollDisplayRight();
|
||||
void leftToRight();
|
||||
void rightToLeft();
|
||||
void autoscroll();
|
||||
void noAutoscroll();
|
||||
|
||||
void setRowOffsets(int row1, int row2, int row3, int row4);
|
||||
void createChar(uint8_t, uint8_t[]);
|
||||
void setCursor(uint8_t, uint8_t);
|
||||
virtual size_t write(uint8_t);
|
||||
void command(uint8_t);
|
||||
|
||||
using Print::write;
|
||||
private:
|
||||
void send(uint8_t, uint8_t);
|
||||
void write4bits(uint8_t);
|
||||
void write8bits(uint8_t);
|
||||
void pulseEnable();
|
||||
|
||||
uint8_t _rs_pin; // LOW: command. HIGH: character.
|
||||
uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD.
|
||||
uint8_t _enable_pin; // activated by a HIGH pulse.
|
||||
uint8_t _data_pins[8];
|
||||
|
||||
uint8_t _displayfunction;
|
||||
uint8_t _displaycontrol;
|
||||
uint8_t _displaymode;
|
||||
|
||||
uint8_t _initialized;
|
||||
|
||||
uint8_t _numlines;
|
||||
uint8_t _row_offsets[4];
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,23 @@
|
||||
MPU6050 Arduino Library 1.0.3 / 03.03.2015
|
||||
======================================================================
|
||||
|
||||
* Added setDLPFMode(mpu6050_dlpf_t dlpf) function
|
||||
MPU6050_DLPF_0...6 (see datatsheet)
|
||||
|
||||
MPU6050 Arduino Library 1.0.2 / 10.02.2015
|
||||
======================================================================
|
||||
|
||||
* Adjustable i2c address
|
||||
mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G) - default 0x68
|
||||
mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G, 0x69) - use 0x69
|
||||
|
||||
MPU6050 Arduino Library 1.0.1 / 26.10.2014
|
||||
======================================================================
|
||||
|
||||
* Removing examples for Kalman Filter. Moved to KalmanFilter Git repo
|
||||
* Removing examples for HMC5883L. Moved to HMC5833L Git repo
|
||||
|
||||
MPU6050 Arduino Library 1.0.0 / 20.10.2014
|
||||
======================================================================
|
||||
|
||||
* First release
|
||||
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, 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
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If 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 convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{one line to give the program's name and a brief idea of what it does.}
|
||||
Copyright (C) {year} {name of author}
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
@ -0,0 +1,749 @@
|
||||
/*
|
||||
MPU6050.cpp - Class file for the MPU6050 Triple Axis Gyroscope & Accelerometer Arduino Library.
|
||||
|
||||
Version: 1.0.3
|
||||
(c) 2014-2015 Korneliusz Jarzebski
|
||||
www.jarzebski.pl
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the version 3 GNU General Public License as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#include <Wire.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <MPU6050.h>
|
||||
|
||||
bool MPU6050::begin(mpu6050_dps_t scale, mpu6050_range_t range, int mpua)
|
||||
{
|
||||
// Set Address
|
||||
mpuAddress = mpua;
|
||||
|
||||
Wire.begin();
|
||||
|
||||
// Reset calibrate values
|
||||
dg.XAxis = 0;
|
||||
dg.YAxis = 0;
|
||||
dg.ZAxis = 0;
|
||||
useCalibrate = false;
|
||||
|
||||
// Reset threshold values
|
||||
tg.XAxis = 0;
|
||||
tg.YAxis = 0;
|
||||
tg.ZAxis = 0;
|
||||
actualThreshold = 0;
|
||||
|
||||
// Check MPU6050 Who Am I Register
|
||||
if (fastRegister8(MPU6050_REG_WHO_AM_I) != 0x68)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set Clock Source
|
||||
setClockSource(MPU6050_CLOCK_PLL_XGYRO);
|
||||
|
||||
// Set Scale & Range
|
||||
setScale(scale);
|
||||
setRange(range);
|
||||
|
||||
// Disable Sleep Mode
|
||||
setSleepEnabled(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MPU6050::setScale(mpu6050_dps_t scale)
|
||||
{
|
||||
uint8_t value;
|
||||
|
||||
switch (scale)
|
||||
{
|
||||
case MPU6050_SCALE_250DPS:
|
||||
dpsPerDigit = .007633f;
|
||||
break;
|
||||
case MPU6050_SCALE_500DPS:
|
||||
dpsPerDigit = .015267f;
|
||||
break;
|
||||
case MPU6050_SCALE_1000DPS:
|
||||
dpsPerDigit = .030487f;
|
||||
break;
|
||||
case MPU6050_SCALE_2000DPS:
|
||||
dpsPerDigit = .060975f;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
value = readRegister8(MPU6050_REG_GYRO_CONFIG);
|
||||
value &= 0b11100111;
|
||||
value |= (scale << 3);
|
||||
writeRegister8(MPU6050_REG_GYRO_CONFIG, value);
|
||||
}
|
||||
|
||||
mpu6050_dps_t MPU6050::getScale(void)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_GYRO_CONFIG);
|
||||
value &= 0b00011000;
|
||||
value >>= 3;
|
||||
return (mpu6050_dps_t)value;
|
||||
}
|
||||
|
||||
void MPU6050::setRange(mpu6050_range_t range)
|
||||
{
|
||||
uint8_t value;
|
||||
|
||||
switch (range)
|
||||
{
|
||||
case MPU6050_RANGE_2G:
|
||||
rangePerDigit = .000061f;
|
||||
break;
|
||||
case MPU6050_RANGE_4G:
|
||||
rangePerDigit = .000122f;
|
||||
break;
|
||||
case MPU6050_RANGE_8G:
|
||||
rangePerDigit = .000244f;
|
||||
break;
|
||||
case MPU6050_RANGE_16G:
|
||||
rangePerDigit = .0004882f;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
value = readRegister8(MPU6050_REG_ACCEL_CONFIG);
|
||||
value &= 0b11100111;
|
||||
value |= (range << 3);
|
||||
writeRegister8(MPU6050_REG_ACCEL_CONFIG, value);
|
||||
}
|
||||
|
||||
mpu6050_range_t MPU6050::getRange(void)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_ACCEL_CONFIG);
|
||||
value &= 0b00011000;
|
||||
value >>= 3;
|
||||
return (mpu6050_range_t)value;
|
||||
}
|
||||
|
||||
void MPU6050::setDHPFMode(mpu6050_dhpf_t dhpf)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_ACCEL_CONFIG);
|
||||
value &= 0b11111000;
|
||||
value |= dhpf;
|
||||
writeRegister8(MPU6050_REG_ACCEL_CONFIG, value);
|
||||
}
|
||||
|
||||
void MPU6050::setDLPFMode(mpu6050_dlpf_t dlpf)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_CONFIG);
|
||||
value &= 0b11111000;
|
||||
value |= dlpf;
|
||||
writeRegister8(MPU6050_REG_CONFIG, value);
|
||||
}
|
||||
|
||||
void MPU6050::setClockSource(mpu6050_clockSource_t source)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_PWR_MGMT_1);
|
||||
value &= 0b11111000;
|
||||
value |= source;
|
||||
writeRegister8(MPU6050_REG_PWR_MGMT_1, value);
|
||||
}
|
||||
|
||||
mpu6050_clockSource_t MPU6050::getClockSource(void)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_PWR_MGMT_1);
|
||||
value &= 0b00000111;
|
||||
return (mpu6050_clockSource_t)value;
|
||||
}
|
||||
|
||||
bool MPU6050::getSleepEnabled(void)
|
||||
{
|
||||
return readRegisterBit(MPU6050_REG_PWR_MGMT_1, 6);
|
||||
}
|
||||
|
||||
void MPU6050::setSleepEnabled(bool state)
|
||||
{
|
||||
writeRegisterBit(MPU6050_REG_PWR_MGMT_1, 6, state);
|
||||
}
|
||||
|
||||
bool MPU6050::getIntZeroMotionEnabled(void)
|
||||
{
|
||||
return readRegisterBit(MPU6050_REG_INT_ENABLE, 5);
|
||||
}
|
||||
|
||||
void MPU6050::setIntZeroMotionEnabled(bool state)
|
||||
{
|
||||
writeRegisterBit(MPU6050_REG_INT_ENABLE, 5, state);
|
||||
}
|
||||
|
||||
bool MPU6050::getIntMotionEnabled(void)
|
||||
{
|
||||
return readRegisterBit(MPU6050_REG_INT_ENABLE, 6);
|
||||
}
|
||||
|
||||
void MPU6050::setIntMotionEnabled(bool state)
|
||||
{
|
||||
writeRegisterBit(MPU6050_REG_INT_ENABLE, 6, state);
|
||||
}
|
||||
|
||||
bool MPU6050::getIntFreeFallEnabled(void)
|
||||
{
|
||||
return readRegisterBit(MPU6050_REG_INT_ENABLE, 7);
|
||||
}
|
||||
|
||||
void MPU6050::setIntFreeFallEnabled(bool state)
|
||||
{
|
||||
writeRegisterBit(MPU6050_REG_INT_ENABLE, 7, state);
|
||||
}
|
||||
|
||||
uint8_t MPU6050::getMotionDetectionThreshold(void)
|
||||
{
|
||||
return readRegister8(MPU6050_REG_MOT_THRESHOLD);
|
||||
}
|
||||
|
||||
void MPU6050::setMotionDetectionThreshold(uint8_t threshold)
|
||||
{
|
||||
writeRegister8(MPU6050_REG_MOT_THRESHOLD, threshold);
|
||||
}
|
||||
|
||||
uint8_t MPU6050::getMotionDetectionDuration(void)
|
||||
{
|
||||
return readRegister8(MPU6050_REG_MOT_DURATION);
|
||||
}
|
||||
|
||||
void MPU6050::setMotionDetectionDuration(uint8_t duration)
|
||||
{
|
||||
writeRegister8(MPU6050_REG_MOT_DURATION, duration);
|
||||
}
|
||||
|
||||
uint8_t MPU6050::getZeroMotionDetectionThreshold(void)
|
||||
{
|
||||
return readRegister8(MPU6050_REG_ZMOT_THRESHOLD);
|
||||
}
|
||||
|
||||
void MPU6050::setZeroMotionDetectionThreshold(uint8_t threshold)
|
||||
{
|
||||
writeRegister8(MPU6050_REG_ZMOT_THRESHOLD, threshold);
|
||||
}
|
||||
|
||||
uint8_t MPU6050::getZeroMotionDetectionDuration(void)
|
||||
{
|
||||
return readRegister8(MPU6050_REG_ZMOT_DURATION);
|
||||
}
|
||||
|
||||
void MPU6050::setZeroMotionDetectionDuration(uint8_t duration)
|
||||
{
|
||||
writeRegister8(MPU6050_REG_ZMOT_DURATION, duration);
|
||||
}
|
||||
|
||||
uint8_t MPU6050::getFreeFallDetectionThreshold(void)
|
||||
{
|
||||
return readRegister8(MPU6050_REG_FF_THRESHOLD);
|
||||
}
|
||||
|
||||
void MPU6050::setFreeFallDetectionThreshold(uint8_t threshold)
|
||||
{
|
||||
writeRegister8(MPU6050_REG_FF_THRESHOLD, threshold);
|
||||
}
|
||||
|
||||
uint8_t MPU6050::getFreeFallDetectionDuration(void)
|
||||
{
|
||||
return readRegister8(MPU6050_REG_FF_DURATION);
|
||||
}
|
||||
|
||||
void MPU6050::setFreeFallDetectionDuration(uint8_t duration)
|
||||
{
|
||||
writeRegister8(MPU6050_REG_FF_DURATION, duration);
|
||||
}
|
||||
|
||||
bool MPU6050::getI2CMasterModeEnabled(void)
|
||||
{
|
||||
return readRegisterBit(MPU6050_REG_USER_CTRL, 5);
|
||||
}
|
||||
|
||||
void MPU6050::setI2CMasterModeEnabled(bool state)
|
||||
{
|
||||
writeRegisterBit(MPU6050_REG_USER_CTRL, 5, state);
|
||||
}
|
||||
|
||||
void MPU6050::setI2CBypassEnabled(bool state)
|
||||
{
|
||||
return writeRegisterBit(MPU6050_REG_INT_PIN_CFG, 1, state);
|
||||
}
|
||||
|
||||
bool MPU6050::getI2CBypassEnabled(void)
|
||||
{
|
||||
return readRegisterBit(MPU6050_REG_INT_PIN_CFG, 1);
|
||||
}
|
||||
|
||||
void MPU6050::setAccelPowerOnDelay(mpu6050_onDelay_t delay)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_MOT_DETECT_CTRL);
|
||||
value &= 0b11001111;
|
||||
value |= (delay << 4);
|
||||
writeRegister8(MPU6050_REG_MOT_DETECT_CTRL, value);
|
||||
}
|
||||
|
||||
mpu6050_onDelay_t MPU6050::getAccelPowerOnDelay(void)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_MOT_DETECT_CTRL);
|
||||
value &= 0b00110000;
|
||||
return (mpu6050_onDelay_t)(value >> 4);
|
||||
}
|
||||
|
||||
uint8_t MPU6050::getIntStatus(void)
|
||||
{
|
||||
return readRegister8(MPU6050_REG_INT_STATUS);
|
||||
}
|
||||
|
||||
Activites MPU6050::readActivites(void)
|
||||
{
|
||||
uint8_t data = readRegister8(MPU6050_REG_INT_STATUS);
|
||||
|
||||
a.isOverflow = ((data >> 4) & 1);
|
||||
a.isFreeFall = ((data >> 7) & 1);
|
||||
a.isInactivity = ((data >> 5) & 1);
|
||||
a.isActivity = ((data >> 6) & 1);
|
||||
a.isDataReady = ((data >> 0) & 1);
|
||||
|
||||
data = readRegister8(MPU6050_REG_MOT_DETECT_STATUS);
|
||||
|
||||
a.isNegActivityOnX = ((data >> 7) & 1);
|
||||
a.isPosActivityOnX = ((data >> 6) & 1);
|
||||
|
||||
a.isNegActivityOnY = ((data >> 5) & 1);
|
||||
a.isPosActivityOnY = ((data >> 4) & 1);
|
||||
|
||||
a.isNegActivityOnZ = ((data >> 3) & 1);
|
||||
a.isPosActivityOnZ = ((data >> 2) & 1);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
Vector MPU6050::readRawAccel(void)
|
||||
{
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(MPU6050_REG_ACCEL_XOUT_H);
|
||||
#else
|
||||
Wire.send(MPU6050_REG_ACCEL_XOUT_H);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
Wire.requestFrom(mpuAddress, 6);
|
||||
|
||||
while (Wire.available() < 6);
|
||||
|
||||
#if ARDUINO >= 100
|
||||
uint8_t xha = Wire.read();
|
||||
uint8_t xla = Wire.read();
|
||||
uint8_t yha = Wire.read();
|
||||
uint8_t yla = Wire.read();
|
||||
uint8_t zha = Wire.read();
|
||||
uint8_t zla = Wire.read();
|
||||
#else
|
||||
uint8_t xha = Wire.receive();
|
||||
uint8_t xla = Wire.receive();
|
||||
uint8_t yha = Wire.receive();
|
||||
uint8_t yla = Wire.receive();
|
||||
uint8_t zha = Wire.receive();
|
||||
uint8_t zla = Wire.receive();
|
||||
#endif
|
||||
|
||||
ra.XAxis = xha << 8 | xla;
|
||||
ra.YAxis = yha << 8 | yla;
|
||||
ra.ZAxis = zha << 8 | zla;
|
||||
|
||||
return ra;
|
||||
}
|
||||
|
||||
Vector MPU6050::readNormalizeAccel(void)
|
||||
{
|
||||
readRawAccel();
|
||||
|
||||
na.XAxis = ra.XAxis * rangePerDigit * 9.80665f;
|
||||
na.YAxis = ra.YAxis * rangePerDigit * 9.80665f;
|
||||
na.ZAxis = ra.ZAxis * rangePerDigit * 9.80665f;
|
||||
|
||||
return na;
|
||||
}
|
||||
|
||||
Vector MPU6050::readScaledAccel(void)
|
||||
{
|
||||
readRawAccel();
|
||||
|
||||
na.XAxis = ra.XAxis * rangePerDigit;
|
||||
na.YAxis = ra.YAxis * rangePerDigit;
|
||||
na.ZAxis = ra.ZAxis * rangePerDigit;
|
||||
|
||||
return na;
|
||||
}
|
||||
|
||||
|
||||
Vector MPU6050::readRawGyro(void)
|
||||
{
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(MPU6050_REG_GYRO_XOUT_H);
|
||||
#else
|
||||
Wire.send(MPU6050_REG_GYRO_XOUT_H);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
Wire.requestFrom(mpuAddress, 6);
|
||||
|
||||
while (Wire.available() < 6);
|
||||
|
||||
#if ARDUINO >= 100
|
||||
uint8_t xha = Wire.read();
|
||||
uint8_t xla = Wire.read();
|
||||
uint8_t yha = Wire.read();
|
||||
uint8_t yla = Wire.read();
|
||||
uint8_t zha = Wire.read();
|
||||
uint8_t zla = Wire.read();
|
||||
#else
|
||||
uint8_t xha = Wire.receive();
|
||||
uint8_t xla = Wire.receive();
|
||||
uint8_t yha = Wire.receive();
|
||||
uint8_t yla = Wire.receive();
|
||||
uint8_t zha = Wire.receive();
|
||||
uint8_t zla = Wire.receive();
|
||||
#endif
|
||||
|
||||
rg.XAxis = xha << 8 | xla;
|
||||
rg.YAxis = yha << 8 | yla;
|
||||
rg.ZAxis = zha << 8 | zla;
|
||||
|
||||
return rg;
|
||||
}
|
||||
|
||||
Vector MPU6050::readNormalizeGyro(void)
|
||||
{
|
||||
readRawGyro();
|
||||
|
||||
if (useCalibrate)
|
||||
{
|
||||
ng.XAxis = (rg.XAxis - dg.XAxis) * dpsPerDigit;
|
||||
ng.YAxis = (rg.YAxis - dg.YAxis) * dpsPerDigit;
|
||||
ng.ZAxis = (rg.ZAxis - dg.ZAxis) * dpsPerDigit;
|
||||
} else
|
||||
{
|
||||
ng.XAxis = rg.XAxis * dpsPerDigit;
|
||||
ng.YAxis = rg.YAxis * dpsPerDigit;
|
||||
ng.ZAxis = rg.ZAxis * dpsPerDigit;
|
||||
}
|
||||
|
||||
if (actualThreshold)
|
||||
{
|
||||
if (abs(ng.XAxis) < tg.XAxis) ng.XAxis = 0;
|
||||
if (abs(ng.YAxis) < tg.YAxis) ng.YAxis = 0;
|
||||
if (abs(ng.ZAxis) < tg.ZAxis) ng.ZAxis = 0;
|
||||
}
|
||||
|
||||
return ng;
|
||||
}
|
||||
|
||||
float MPU6050::readTemperature(void)
|
||||
{
|
||||
int16_t T;
|
||||
T = readRegister16(MPU6050_REG_TEMP_OUT_H);
|
||||
return (float)T/340 + 36.53;
|
||||
}
|
||||
|
||||
int16_t MPU6050::getGyroOffsetX(void)
|
||||
{
|
||||
return readRegister16(MPU6050_REG_GYRO_XOFFS_H);
|
||||
}
|
||||
|
||||
int16_t MPU6050::getGyroOffsetY(void)
|
||||
{
|
||||
return readRegister16(MPU6050_REG_GYRO_YOFFS_H);
|
||||
}
|
||||
|
||||
int16_t MPU6050::getGyroOffsetZ(void)
|
||||
{
|
||||
return readRegister16(MPU6050_REG_GYRO_ZOFFS_H);
|
||||
}
|
||||
|
||||
void MPU6050::setGyroOffsetX(int16_t offset)
|
||||
{
|
||||
writeRegister16(MPU6050_REG_GYRO_XOFFS_H, offset);
|
||||
}
|
||||
|
||||
void MPU6050::setGyroOffsetY(int16_t offset)
|
||||
{
|
||||
writeRegister16(MPU6050_REG_GYRO_YOFFS_H, offset);
|
||||
}
|
||||
|
||||
void MPU6050::setGyroOffsetZ(int16_t offset)
|
||||
{
|
||||
writeRegister16(MPU6050_REG_GYRO_ZOFFS_H, offset);
|
||||
}
|
||||
|
||||
int16_t MPU6050::getAccelOffsetX(void)
|
||||
{
|
||||
return readRegister16(MPU6050_REG_ACCEL_XOFFS_H);
|
||||
}
|
||||
|
||||
int16_t MPU6050::getAccelOffsetY(void)
|
||||
{
|
||||
return readRegister16(MPU6050_REG_ACCEL_YOFFS_H);
|
||||
}
|
||||
|
||||
int16_t MPU6050::getAccelOffsetZ(void)
|
||||
{
|
||||
return readRegister16(MPU6050_REG_ACCEL_ZOFFS_H);
|
||||
}
|
||||
|
||||
void MPU6050::setAccelOffsetX(int16_t offset)
|
||||
{
|
||||
writeRegister16(MPU6050_REG_ACCEL_XOFFS_H, offset);
|
||||
}
|
||||
|
||||
void MPU6050::setAccelOffsetY(int16_t offset)
|
||||
{
|
||||
writeRegister16(MPU6050_REG_ACCEL_YOFFS_H, offset);
|
||||
}
|
||||
|
||||
void MPU6050::setAccelOffsetZ(int16_t offset)
|
||||
{
|
||||
writeRegister16(MPU6050_REG_ACCEL_ZOFFS_H, offset);
|
||||
}
|
||||
|
||||
// Calibrate algorithm
|
||||
void MPU6050::calibrateGyro(uint8_t samples)
|
||||
{
|
||||
// Set calibrate
|
||||
useCalibrate = true;
|
||||
|
||||
// Reset values
|
||||
float sumX = 0;
|
||||
float sumY = 0;
|
||||
float sumZ = 0;
|
||||
float sigmaX = 0;
|
||||
float sigmaY = 0;
|
||||
float sigmaZ = 0;
|
||||
|
||||
// Read n-samples
|
||||
for (uint8_t i = 0; i < samples; ++i)
|
||||
{
|
||||
readRawGyro();
|
||||
sumX += rg.XAxis;
|
||||
sumY += rg.YAxis;
|
||||
sumZ += rg.ZAxis;
|
||||
|
||||
sigmaX += rg.XAxis * rg.XAxis;
|
||||
sigmaY += rg.YAxis * rg.YAxis;
|
||||
sigmaZ += rg.ZAxis * rg.ZAxis;
|
||||
|
||||
delay(5);
|
||||
}
|
||||
|
||||
// Calculate delta vectors
|
||||
dg.XAxis = sumX / samples;
|
||||
dg.YAxis = sumY / samples;
|
||||
dg.ZAxis = sumZ / samples;
|
||||
|
||||
// Calculate threshold vectors
|
||||
th.XAxis = sqrt((sigmaX / 50) - (dg.XAxis * dg.XAxis));
|
||||
th.YAxis = sqrt((sigmaY / 50) - (dg.YAxis * dg.YAxis));
|
||||
th.ZAxis = sqrt((sigmaZ / 50) - (dg.ZAxis * dg.ZAxis));
|
||||
|
||||
// If already set threshold, recalculate threshold vectors
|
||||
if (actualThreshold > 0)
|
||||
{
|
||||
setThreshold(actualThreshold);
|
||||
}
|
||||
}
|
||||
|
||||
// Get current threshold value
|
||||
uint8_t MPU6050::getThreshold(void)
|
||||
{
|
||||
return actualThreshold;
|
||||
}
|
||||
|
||||
// Set treshold value
|
||||
void MPU6050::setThreshold(uint8_t multiple)
|
||||
{
|
||||
if (multiple > 0)
|
||||
{
|
||||
// If not calibrated, need calibrate
|
||||
if (!useCalibrate)
|
||||
{
|
||||
calibrateGyro();
|
||||
}
|
||||
|
||||
// Calculate threshold vectors
|
||||
tg.XAxis = th.XAxis * multiple;
|
||||
tg.YAxis = th.YAxis * multiple;
|
||||
tg.ZAxis = th.ZAxis * multiple;
|
||||
} else
|
||||
{
|
||||
// No threshold
|
||||
tg.XAxis = 0;
|
||||
tg.YAxis = 0;
|
||||
tg.ZAxis = 0;
|
||||
}
|
||||
|
||||
// Remember old threshold value
|
||||
actualThreshold = multiple;
|
||||
}
|
||||
|
||||
// Fast read 8-bit from register
|
||||
uint8_t MPU6050::fastRegister8(uint8_t reg)
|
||||
{
|
||||
uint8_t value;
|
||||
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(reg);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
Wire.requestFrom(mpuAddress, 1);
|
||||
#if ARDUINO >= 100
|
||||
value = Wire.read();
|
||||
#else
|
||||
value = Wire.receive();
|
||||
#endif;
|
||||
Wire.endTransmission();
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
// Read 8-bit from register
|
||||
uint8_t MPU6050::readRegister8(uint8_t reg)
|
||||
{
|
||||
uint8_t value;
|
||||
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(reg);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
Wire.requestFrom(mpuAddress, 1);
|
||||
while(!Wire.available()) {};
|
||||
#if ARDUINO >= 100
|
||||
value = Wire.read();
|
||||
#else
|
||||
value = Wire.receive();
|
||||
#endif;
|
||||
Wire.endTransmission();
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
// Write 8-bit to register
|
||||
void MPU6050::writeRegister8(uint8_t reg, uint8_t value)
|
||||
{
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(reg);
|
||||
Wire.write(value);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
Wire.send(value);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
int16_t MPU6050::readRegister16(uint8_t reg)
|
||||
{
|
||||
int16_t value;
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(reg);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
Wire.requestFrom(mpuAddress, 2);
|
||||
while(!Wire.available()) {};
|
||||
#if ARDUINO >= 100
|
||||
uint8_t vha = Wire.read();
|
||||
uint8_t vla = Wire.read();
|
||||
#else
|
||||
uint8_t vha = Wire.receive();
|
||||
uint8_t vla = Wire.receive();
|
||||
#endif;
|
||||
Wire.endTransmission();
|
||||
|
||||
value = vha << 8 | vla;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void MPU6050::writeRegister16(uint8_t reg, int16_t value)
|
||||
{
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(reg);
|
||||
Wire.write((uint8_t)(value >> 8));
|
||||
Wire.write((uint8_t)value);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
Wire.send((uint8_t)(value >> 8));
|
||||
Wire.send((uint8_t)value);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
// Read register bit
|
||||
bool MPU6050::readRegisterBit(uint8_t reg, uint8_t pos)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(reg);
|
||||
return ((value >> pos) & 1);
|
||||
}
|
||||
|
||||
// Write register bit
|
||||
void MPU6050::writeRegisterBit(uint8_t reg, uint8_t pos, bool state)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(reg);
|
||||
|
||||
if (state)
|
||||
{
|
||||
value |= (1 << pos);
|
||||
} else
|
||||
{
|
||||
value &= ~(1 << pos);
|
||||
}
|
||||
|
||||
writeRegister8(reg, value);
|
||||
}
|
||||
@ -0,0 +1,258 @@
|
||||
/*
|
||||
MPU6050.h - Header file for the MPU6050 Triple Axis Gyroscope & Accelerometer Arduino Library.
|
||||
|
||||
Version: 1.0.3
|
||||
(c) 2014-2015 Korneliusz Jarzebski
|
||||
www.jarzebski.pl
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the version 3 GNU General Public License as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MPU6050_h
|
||||
#define MPU6050_h
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#define MPU6050_ADDRESS (0x68) // 0x69 when AD0 pin to Vcc
|
||||
|
||||
#define MPU6050_REG_ACCEL_XOFFS_H (0x06)
|
||||
#define MPU6050_REG_ACCEL_XOFFS_L (0x07)
|
||||
#define MPU6050_REG_ACCEL_YOFFS_H (0x08)
|
||||
#define MPU6050_REG_ACCEL_YOFFS_L (0x09)
|
||||
#define MPU6050_REG_ACCEL_ZOFFS_H (0x0A)
|
||||
#define MPU6050_REG_ACCEL_ZOFFS_L (0x0B)
|
||||
#define MPU6050_REG_GYRO_XOFFS_H (0x13)
|
||||
#define MPU6050_REG_GYRO_XOFFS_L (0x14)
|
||||
#define MPU6050_REG_GYRO_YOFFS_H (0x15)
|
||||
#define MPU6050_REG_GYRO_YOFFS_L (0x16)
|
||||
#define MPU6050_REG_GYRO_ZOFFS_H (0x17)
|
||||
#define MPU6050_REG_GYRO_ZOFFS_L (0x18)
|
||||
#define MPU6050_REG_CONFIG (0x1A)
|
||||
#define MPU6050_REG_GYRO_CONFIG (0x1B) // Gyroscope Configuration
|
||||
#define MPU6050_REG_ACCEL_CONFIG (0x1C) // Accelerometer Configuration
|
||||
#define MPU6050_REG_FF_THRESHOLD (0x1D)
|
||||
#define MPU6050_REG_FF_DURATION (0x1E)
|
||||
#define MPU6050_REG_MOT_THRESHOLD (0x1F)
|
||||
#define MPU6050_REG_MOT_DURATION (0x20)
|
||||
#define MPU6050_REG_ZMOT_THRESHOLD (0x21)
|
||||
#define MPU6050_REG_ZMOT_DURATION (0x22)
|
||||
#define MPU6050_REG_INT_PIN_CFG (0x37) // INT Pin. Bypass Enable Configuration
|
||||
#define MPU6050_REG_INT_ENABLE (0x38) // INT Enable
|
||||
#define MPU6050_REG_INT_STATUS (0x3A)
|
||||
#define MPU6050_REG_ACCEL_XOUT_H (0x3B)
|
||||
#define MPU6050_REG_ACCEL_XOUT_L (0x3C)
|
||||
#define MPU6050_REG_ACCEL_YOUT_H (0x3D)
|
||||
#define MPU6050_REG_ACCEL_YOUT_L (0x3E)
|
||||
#define MPU6050_REG_ACCEL_ZOUT_H (0x3F)
|
||||
#define MPU6050_REG_ACCEL_ZOUT_L (0x40)
|
||||
#define MPU6050_REG_TEMP_OUT_H (0x41)
|
||||
#define MPU6050_REG_TEMP_OUT_L (0x42)
|
||||
#define MPU6050_REG_GYRO_XOUT_H (0x43)
|
||||
#define MPU6050_REG_GYRO_XOUT_L (0x44)
|
||||
#define MPU6050_REG_GYRO_YOUT_H (0x45)
|
||||
#define MPU6050_REG_GYRO_YOUT_L (0x46)
|
||||
#define MPU6050_REG_GYRO_ZOUT_H (0x47)
|
||||
#define MPU6050_REG_GYRO_ZOUT_L (0x48)
|
||||
#define MPU6050_REG_MOT_DETECT_STATUS (0x61)
|
||||
#define MPU6050_REG_MOT_DETECT_CTRL (0x69)
|
||||
#define MPU6050_REG_USER_CTRL (0x6A) // User Control
|
||||
#define MPU6050_REG_PWR_MGMT_1 (0x6B) // Power Management 1
|
||||
#define MPU6050_REG_WHO_AM_I (0x75) // Who Am I
|
||||
|
||||
#ifndef VECTOR_STRUCT_H
|
||||
#define VECTOR_STRUCT_H
|
||||
struct Vector
|
||||
{
|
||||
float XAxis;
|
||||
float YAxis;
|
||||
float ZAxis;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct Activites
|
||||
{
|
||||
bool isOverflow;
|
||||
bool isFreeFall;
|
||||
bool isInactivity;
|
||||
bool isActivity;
|
||||
bool isPosActivityOnX;
|
||||
bool isPosActivityOnY;
|
||||
bool isPosActivityOnZ;
|
||||
bool isNegActivityOnX;
|
||||
bool isNegActivityOnY;
|
||||
bool isNegActivityOnZ;
|
||||
bool isDataReady;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MPU6050_CLOCK_KEEP_RESET = 0b111,
|
||||
MPU6050_CLOCK_EXTERNAL_19MHZ = 0b101,
|
||||
MPU6050_CLOCK_EXTERNAL_32KHZ = 0b100,
|
||||
MPU6050_CLOCK_PLL_ZGYRO = 0b011,
|
||||
MPU6050_CLOCK_PLL_YGYRO = 0b010,
|
||||
MPU6050_CLOCK_PLL_XGYRO = 0b001,
|
||||
MPU6050_CLOCK_INTERNAL_8MHZ = 0b000
|
||||
} mpu6050_clockSource_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MPU6050_SCALE_2000DPS = 0b11,
|
||||
MPU6050_SCALE_1000DPS = 0b10,
|
||||
MPU6050_SCALE_500DPS = 0b01,
|
||||
MPU6050_SCALE_250DPS = 0b00
|
||||
} mpu6050_dps_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MPU6050_RANGE_16G = 0b11,
|
||||
MPU6050_RANGE_8G = 0b10,
|
||||
MPU6050_RANGE_4G = 0b01,
|
||||
MPU6050_RANGE_2G = 0b00,
|
||||
} mpu6050_range_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MPU6050_DELAY_3MS = 0b11,
|
||||
MPU6050_DELAY_2MS = 0b10,
|
||||
MPU6050_DELAY_1MS = 0b01,
|
||||
MPU6050_NO_DELAY = 0b00,
|
||||
} mpu6050_onDelay_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MPU6050_DHPF_HOLD = 0b111,
|
||||
MPU6050_DHPF_0_63HZ = 0b100,
|
||||
MPU6050_DHPF_1_25HZ = 0b011,
|
||||
MPU6050_DHPF_2_5HZ = 0b010,
|
||||
MPU6050_DHPF_5HZ = 0b001,
|
||||
MPU6050_DHPF_RESET = 0b000,
|
||||
} mpu6050_dhpf_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MPU6050_DLPF_6 = 0b110,
|
||||
MPU6050_DLPF_5 = 0b101,
|
||||
MPU6050_DLPF_4 = 0b100,
|
||||
MPU6050_DLPF_3 = 0b011,
|
||||
MPU6050_DLPF_2 = 0b010,
|
||||
MPU6050_DLPF_1 = 0b001,
|
||||
MPU6050_DLPF_0 = 0b000,
|
||||
} mpu6050_dlpf_t;
|
||||
|
||||
class MPU6050
|
||||
{
|
||||
public:
|
||||
|
||||
bool begin(mpu6050_dps_t scale = MPU6050_SCALE_2000DPS, mpu6050_range_t range = MPU6050_RANGE_2G, int mpua = MPU6050_ADDRESS);
|
||||
|
||||
void setClockSource(mpu6050_clockSource_t source);
|
||||
void setScale(mpu6050_dps_t scale);
|
||||
void setRange(mpu6050_range_t range);
|
||||
mpu6050_clockSource_t getClockSource(void);
|
||||
mpu6050_dps_t getScale(void);
|
||||
mpu6050_range_t getRange(void);
|
||||
void setDHPFMode(mpu6050_dhpf_t dhpf);
|
||||
void setDLPFMode(mpu6050_dlpf_t dlpf);
|
||||
mpu6050_onDelay_t getAccelPowerOnDelay();
|
||||
void setAccelPowerOnDelay(mpu6050_onDelay_t delay);
|
||||
|
||||
uint8_t getIntStatus(void);
|
||||
|
||||
bool getIntZeroMotionEnabled(void);
|
||||
void setIntZeroMotionEnabled(bool state);
|
||||
bool getIntMotionEnabled(void);
|
||||
void setIntMotionEnabled(bool state);
|
||||
bool getIntFreeFallEnabled(void);
|
||||
void setIntFreeFallEnabled(bool state);
|
||||
|
||||
uint8_t getMotionDetectionThreshold(void);
|
||||
void setMotionDetectionThreshold(uint8_t threshold);
|
||||
uint8_t getMotionDetectionDuration(void);
|
||||
void setMotionDetectionDuration(uint8_t duration);
|
||||
|
||||
uint8_t getZeroMotionDetectionThreshold(void);
|
||||
void setZeroMotionDetectionThreshold(uint8_t threshold);
|
||||
uint8_t getZeroMotionDetectionDuration(void);
|
||||
void setZeroMotionDetectionDuration(uint8_t duration);
|
||||
|
||||
uint8_t getFreeFallDetectionThreshold(void);
|
||||
void setFreeFallDetectionThreshold(uint8_t threshold);
|
||||
uint8_t getFreeFallDetectionDuration(void);
|
||||
void setFreeFallDetectionDuration(uint8_t duration);
|
||||
|
||||
bool getSleepEnabled(void);
|
||||
void setSleepEnabled(bool state);
|
||||
bool getI2CMasterModeEnabled(void);
|
||||
void setI2CMasterModeEnabled(bool state);
|
||||
bool getI2CBypassEnabled(void);
|
||||
void setI2CBypassEnabled(bool state);
|
||||
|
||||
float readTemperature(void);
|
||||
Activites readActivites(void);
|
||||
|
||||
int16_t getGyroOffsetX(void);
|
||||
void setGyroOffsetX(int16_t offset);
|
||||
int16_t getGyroOffsetY(void);
|
||||
void setGyroOffsetY(int16_t offset);
|
||||
int16_t getGyroOffsetZ(void);
|
||||
void setGyroOffsetZ(int16_t offset);
|
||||
|
||||
int16_t getAccelOffsetX(void);
|
||||
void setAccelOffsetX(int16_t offset);
|
||||
int16_t getAccelOffsetY(void);
|
||||
void setAccelOffsetY(int16_t offset);
|
||||
int16_t getAccelOffsetZ(void);
|
||||
void setAccelOffsetZ(int16_t offset);
|
||||
|
||||
void calibrateGyro(uint8_t samples = 50);
|
||||
void setThreshold(uint8_t multiple = 1);
|
||||
uint8_t getThreshold(void);
|
||||
|
||||
Vector readRawGyro(void);
|
||||
Vector readNormalizeGyro(void);
|
||||
|
||||
Vector readRawAccel(void);
|
||||
Vector readNormalizeAccel(void);
|
||||
Vector readScaledAccel(void);
|
||||
|
||||
private:
|
||||
Vector ra, rg; // Raw vectors
|
||||
Vector na, ng; // Normalized vectors
|
||||
Vector tg, dg; // Threshold and Delta for Gyro
|
||||
Vector th; // Threshold
|
||||
Activites a; // Activities
|
||||
|
||||
float dpsPerDigit, rangePerDigit;
|
||||
float actualThreshold;
|
||||
bool useCalibrate;
|
||||
int mpuAddress;
|
||||
|
||||
uint8_t fastRegister8(uint8_t reg);
|
||||
|
||||
uint8_t readRegister8(uint8_t reg);
|
||||
void writeRegister8(uint8_t reg, uint8_t value);
|
||||
|
||||
int16_t readRegister16(uint8_t reg);
|
||||
void writeRegister16(uint8_t reg, int16_t value);
|
||||
|
||||
bool readRegisterBit(uint8_t reg, uint8_t pos);
|
||||
void writeRegisterBit(uint8_t reg, uint8_t pos, bool state);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,10 @@
|
||||
Arduino-MPU6050
|
||||
===============
|
||||
|
||||
MPU6050 Triple Axis Gyroscope & Accelerometer Arduino Library.
|
||||
|
||||

|
||||
|
||||
Tutorials: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-zyroskop-i-akcelerometr-mpu6050.html
|
||||
|
||||
This library use I2C to communicate, 2 pins are required to interface
|
||||
@ -0,0 +1,47 @@
|
||||
/*
|
||||
MPU6050 Triple Axis Gyroscope & Accelerometer. Pitch & Roll Accelerometer Example.
|
||||
Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-zyroskop-i-akcelerometr-mpu6050.html
|
||||
GIT: https://github.com/jarzebski/Arduino-MPU6050
|
||||
Web: http://www.jarzebski.pl
|
||||
(c) 2014 by Korneliusz Jarzebski
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <MPU6050.h>
|
||||
|
||||
MPU6050 mpu;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Initialize MPU6050");
|
||||
|
||||
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
|
||||
{
|
||||
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Read normalized values
|
||||
Vector normAccel = mpu.readNormalizeAccel();
|
||||
|
||||
// Calculate Pitch & Roll
|
||||
int pitch = -(atan2(normAccel.XAxis, sqrt(normAccel.YAxis*normAccel.YAxis + normAccel.ZAxis*normAccel.ZAxis))*180.0)/M_PI;
|
||||
int roll = (atan2(normAccel.YAxis, normAccel.ZAxis)*180.0)/M_PI;
|
||||
|
||||
// Output
|
||||
Serial.print(" Pitch = ");
|
||||
Serial.print(pitch);
|
||||
Serial.print(" Roll = ");
|
||||
Serial.print(roll);
|
||||
|
||||
Serial.println();
|
||||
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user