jeudi 30 juin 2016

Code Arduino : Module I2C

Module I2C




Code Arduino :

#include "Wire.h" // For I2C
#include "LCD.h" // For LCD
#include "LiquidCrystal_I2C.h" // Added library*
//Set the pins on the I2C chip used for LCD connections
//ADDR,EN,R/W,RS,D4,D5,D6,D7
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7); // 0x27 is the default I2C bus address of the backpack-see article
void setup()
{
   // Set off LCD module
   lcd.begin (16,2); // 16 x 2 LCD module
   lcd.setBacklightPin(3,POSITIVE); // BL, BL_POL
   lcd.setBacklight(HIGH);
}
void loop()
{
   lcd.home (); // Set cursor to 0,0
   lcd.setCursor(5,0);
   lcd.print("axeled"); // Custom text
   lcd.setCursor(4,1);
   lcd.print("YouTube"); // Custom text

}

dimanche 12 juin 2016

Code Arduino : Joystick

Joystick




Code Arduino :

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there

}

vendredi 13 mai 2016

Code Arduino : écran LCD afficher différent caractères

Ecran LCD afficher différent caractères




Codes:

Sans potentiomètre :

// 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 backLight = 10;

// 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() {
  
  pinMode(backLight, OUTPUT);
  analogWrite(backLight, 120);
  
  // 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.setCursor(0,0);
  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);
}




lundi 29 février 2016

Code Arduino : écran LCD

Ecran LCD




Codes:

LCD simple:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

void setup() {

  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("HELLO");
}

void loop() {

}

-----------------------------------------------
LCD simple 2lignes:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

void setup() {

  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("HELLO");
  lcd.setCursor(0,1);
  lcd.print("Bonjour");
}

void loop() {

}

-----------------------------------------------
LCD clignotant:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

void setup() {

  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("HELLO");
}

void loop() {
  lcd.noDisplay();
  delay(500);
  lcd.display();
  delay(500);

}

-----------------------------------------------
LCD clignotant 2lignes:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

void setup() {

  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("HELLO");
  lcd.setCursor(0,1);
  lcd.print("Bonjour");
}

void loop() {
  lcd.noDisplay();
  delay(500);
  lcd.display();
  delay(500);

}

-----------------------------------------------
LCD défilement:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

void setup() {

  lcd.begin(16, 2);
  lcd.setCursor(16,0);
  lcd.print("HELLO");
}

void loop() {
  lcd.scrollDisplayLeft();
  delay(300);

}

-----------------------------------------------
LCD défilement 2lignes:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

void setup() {

  lcd.begin(16, 2);
  lcd.setCursor(16,0);
  lcd.print("HELLO");
  lcd.setCursor(16,1);
  lcd.print("Bonjour");
}

void loop() {
  lcd.scrollDisplayLeft();
  delay(300);

}






samedi 6 février 2016

Code Arduino : Photorésistance

Photorésistance



Code:

int analogPin = 0;
int analogValue = 0;
int ledPin = 7;

void setup() {
 Serial.begin(9600);
 pinMode(ledPin, OUTPUT);
}

void loop() {
  analogValue = analogRead(analogPin);
  Serial.println(analogValue);
  if (analogValue > 400){
    digitalWrite(ledPin, LOW);
  }
  else{
    digitalWrite(ledPin, HIGH);
  }


}



lundi 1 février 2016

Code Arduino : Servo-moteur

Servo-moteur


Code:

#include <Servo.h>

Servo myservo;  

int potpin = 0;  
int val;    n

void setup()
{
  myservo.attach(9);  
}

void loop() 

  val = analogRead(potpin);