added arduino sources
This commit is contained in:
parent
d2d82f4803
commit
87335a7750
52
Blink.ino
Normal file
52
Blink.ino
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
Blink
|
||||
Turns on an LED on for one second, then off for one second, repeatedly.
|
||||
|
||||
Most Arduinos have an on-board LED you can control. On the Uno and
|
||||
Leonardo, it is attached to digital pin 13. If you're unsure what
|
||||
pin the on-board LED is connected to on your Arduino model, check
|
||||
the documentation at http://www.arduino.cc
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
modified 8 May 2014
|
||||
by Scott Fitzgerald
|
||||
*/
|
||||
|
||||
const int ledmin = 8;
|
||||
const int ledmax = 13;
|
||||
const int leds = ledmax - ledmin;
|
||||
|
||||
int Delay = 500/leds;
|
||||
|
||||
// the setup function runs once when you press reset or power the board
|
||||
void setup() {
|
||||
// initialize digital pin 13 as an output.
|
||||
for (int i = ledmin; i <= ledmax; i++)
|
||||
{
|
||||
pinMode(i, OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
// the loop function runs over and over again forever
|
||||
void loop() {
|
||||
up();
|
||||
down();
|
||||
}
|
||||
|
||||
void up() {
|
||||
for (int i = ledmax; i >= ledmin; i--)
|
||||
{
|
||||
digitalWrite(i, HIGH);
|
||||
delay(Delay);
|
||||
}
|
||||
}
|
||||
|
||||
void down() {
|
||||
for (int i = ledmax; i >= ledmin; i--)
|
||||
{
|
||||
digitalWrite(i, LOW);
|
||||
delay(Delay);
|
||||
}
|
||||
}
|
||||
|
56
SoftwareSerialExample.ino
Normal file
56
SoftwareSerialExample.ino
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
Software serial multple serial test
|
||||
|
||||
Receives from the hardware serial, sends to software serial.
|
||||
Receives from software serial, sends to hardware serial.
|
||||
|
||||
The circuit:
|
||||
* RX is digital pin 10 (connect to TX of other device)
|
||||
* TX is digital pin 11 (connect to RX of other device)
|
||||
|
||||
Note:
|
||||
Not all pins on the Mega and Mega 2560 support change interrupts,
|
||||
so only the following can be used for RX:
|
||||
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
|
||||
|
||||
Not all pins on the Leonardo support change interrupts,
|
||||
so only the following can be used for RX:
|
||||
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
|
||||
|
||||
created back in the mists of time
|
||||
modified 25 May 2012
|
||||
by Tom Igoe
|
||||
based on Mikal Hart's example
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
SoftwareSerial mySerial(10, 11); // RX, TX
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(57600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
|
||||
Serial.println("Goodnight moon!");
|
||||
Serial.println("blabla\n");
|
||||
|
||||
// set the data rate for the SoftwareSerial port
|
||||
mySerial.begin(4800);
|
||||
mySerial.println("Hello, world?");
|
||||
}
|
||||
|
||||
void loop() { // run over and over
|
||||
if (mySerial.available()) {
|
||||
Serial.write(mySerial.read());
|
||||
}
|
||||
if (Serial.available()) {
|
||||
mySerial.write(Serial.read());
|
||||
}
|
||||
}
|
||||
|
72
bluetooth_blink.ino
Normal file
72
bluetooth_blink.ino
Normal file
@ -0,0 +1,72 @@
|
||||
#define HC06 Serial1
|
||||
const int Delay = 100;
|
||||
bool var = false;
|
||||
int ledmin = 8;
|
||||
int ledmax = 13;
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
Serial.begin(9600);
|
||||
|
||||
// init module bluetooth
|
||||
HC06.begin(9600);
|
||||
|
||||
// init sorties leds
|
||||
for (int i = 13; i >= 6; i--) {
|
||||
pinMode(i, OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
while (HC06.available())
|
||||
{
|
||||
char data = HC06.read();
|
||||
Serial.write(data);
|
||||
|
||||
if (data == 'A')
|
||||
{
|
||||
blink(true);
|
||||
}
|
||||
if (data == 'B')
|
||||
{
|
||||
blink(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void up(int led, int Delay) {
|
||||
digitalWrite(led, HIGH);
|
||||
delay(Delay);
|
||||
}
|
||||
|
||||
void down(int led, int Delay) {
|
||||
digitalWrite(led, LOW);
|
||||
delay(Delay);
|
||||
}
|
||||
|
||||
int blink(bool dir) {
|
||||
if (dir)
|
||||
{
|
||||
for (int j = ledmax; j >= ledmin; j--) {
|
||||
up(j, Delay);
|
||||
}
|
||||
|
||||
for (int j = ledmax; j >= ledmin; j--) {
|
||||
down(j, Delay);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = ledmin; j <= ledmax; j++) {
|
||||
up(j, Delay);
|
||||
}
|
||||
|
||||
for (int j = ledmin; j <= ledmax; j++) {
|
||||
down(j, Delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
83
i2c_scanner.ino
Normal file
83
i2c_scanner.ino
Normal file
@ -0,0 +1,83 @@
|
||||
// --------------------------------------
|
||||
// i2c_scanner
|
||||
//
|
||||
// Version 1
|
||||
// This program (or code that looks like it)
|
||||
// can be found in many places.
|
||||
// For example on the Arduino.cc forum.
|
||||
// The original author is not know.
|
||||
// Version 2, Juni 2012, Using Arduino 1.0.1
|
||||
// Adapted to be as simple as possible by Arduino.cc user Krodal
|
||||
// Version 3, Feb 26 2013
|
||||
// V3 by louarnold
|
||||
// Version 4, March 3, 2013, Using Arduino 1.0.3
|
||||
// by Arduino.cc user Krodal.
|
||||
// Changes by louarnold removed.
|
||||
// Scanning addresses changed from 0...127 to 1...119,
|
||||
// according to the i2c scanner by Nick Gammon
|
||||
// http://www.gammon.com.au/forum/?id=10896
|
||||
// Version 5, March 28, 2013
|
||||
// As version 4, but address scans now to 127.
|
||||
// A sensor seems to use address 120.
|
||||
// Version 6, November 27, 2015.
|
||||
// Added waiting for the Leonardo serial communication.
|
||||
//
|
||||
//
|
||||
// This sketch tests the standard 7-bit addresses
|
||||
// Devices with higher bit address might not be seen properly.
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Wire.begin();
|
||||
|
||||
Serial.begin(9600);
|
||||
while (!Serial); // Leonardo: wait for serial monitor
|
||||
Serial.println("\nI2C Scanner");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
byte error, address;
|
||||
int nDevices;
|
||||
|
||||
Serial.println("Scanning...");
|
||||
|
||||
nDevices = 0;
|
||||
for(address = 1; address < 127; address++ )
|
||||
{
|
||||
// The i2c_scanner uses the return value of
|
||||
// the Write.endTransmisstion to see if
|
||||
// a device did acknowledge to the address.
|
||||
Wire.beginTransmission(address);
|
||||
error = Wire.endTransmission();
|
||||
|
||||
if (error == 0)
|
||||
{
|
||||
Serial.print("I2C device found at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.print(address,HEX);
|
||||
Serial.println(" !");
|
||||
|
||||
nDevices++;
|
||||
}
|
||||
else if (error==4)
|
||||
{
|
||||
Serial.print("Unknow error at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.println(address,HEX);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
Serial.println("No I2C devices found\n");
|
||||
else
|
||||
Serial.println("done\n");
|
||||
|
||||
delay(5000); // wait 5 seconds for next scan
|
||||
}
|
81
lcd_arduino.ino
Normal file
81
lcd_arduino.ino
Normal file
@ -0,0 +1,81 @@
|
||||
#include <Stream.h>
|
||||
#include <Wire.h>
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
|
||||
LiquidCrystal_I2C lcd (0x3F, 20, 4);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
lcd.begin();
|
||||
lcd.backlight();
|
||||
Elton();
|
||||
|
||||
//lcd.noBacklight();
|
||||
//lcd.autoscroll();
|
||||
//lcd.blink();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
/*
|
||||
// put your main code here, to run repeatedly:
|
||||
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);
|
||||
}
|
||||
|
||||
lcd.scrollDisplayLeft();
|
||||
delay(200);
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// delay at the end of the full loop:
|
||||
//delay(1000);
|
||||
}
|
||||
|
||||
void Elton()
|
||||
{
|
||||
lcd.print("Bonjour Elton");
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print("Manger des");
|
||||
lcd.setCursor(0,2);
|
||||
lcd.print("croquettes ?");
|
||||
lcd.setCursor(0,3);
|
||||
lcd.print("Promener ?");
|
||||
}
|
||||
|
||||
void Kbd()
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user