Vous êtes sur la page 1sur 13

/*

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

*/

// the setup function runs once when you press reset or power the board

void setup() {

// initialize digital pin 13 as an output.

pinMode(13, OUTPUT);

// the loop function runs over and over again forever

void loop() {

digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)

delay(1000); // wait for a second

digitalWrite(13, LOW); // turn the LED off by making the voltage LOW

delay(1000); // wait for a second

}
/*
Fade

This example shows how to fade an LED on pin 9


using the analogWrite() function.

The analogWrite() function uses PWM, so if


you want to change the pin you're using, be
sure to use another PWM capable pin. On most
Arduino, the PWM pins are identified with
a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.

This example code is in the public domain.


*/

int led = 9; // the PWM pin the LED is attached to


int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by

// the setup routine runs once when you press reset:


void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:


void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);

// change the brightness for next time through the loop:


brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:


if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
/*
Button

Turns on and off a light emitting diode(LED) connected to digital


pin 13, when pressing a pushbutton attached to pin 2.

The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
* Note: on most Arduinos there is already an LED on the board
attached to pin 13.
created 2005
by DojoDave <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/Button
*/

// constants won't change. They're used here to


// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

// variables will change:


int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.


// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
/*
Melody

Plays a melody

circuit:
* 8-ohm speaker on digital pin 8

created 21 Jan 2010


modified 30 Aug 2011
by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/Tone

*/
#include "pitches.h"

// notes in the melody:


int melody[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:


int noteDurations[] = {
4, 8, 8, 4, 4, 4, 4, 4
};

void setup() {
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {

// to calculate the note duration, take one second


// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);

// to distinguish the notes, set a minimum time between them.


// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}
}

void loop() {
// no need to repeat the melody.
}
/* for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
Arrays // turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
Demonstrates the use of an array to hold pin numbers delay(timer);
in order to iterate over the pins in a sequence. // turn the pin off:
Lights multiple LEDs in sequence, then in reverse. digitalWrite(ledPins[thisPin], LOW);
}
Unlike the For Loop tutorial, where the pins have to be }
contiguous, here the pins can be in any random order.

The circuit:
* LEDs from pins 2 through 7 to ground

created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/Array
*/

int timer = 100; // The higher the number, the slower


the timing.
int ledPins[] = {
2, 7, 4, 6, 5, 3
}; // an array of pin numbers to which LEDs are attached
int pinCount = 6; // the number of pins (i.e. the length
of the array)

void setup() {
// the array elements are numbered from 0 to (pinCount -
1).
// use a for loop to initialize each pin as an output:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
}

void loop() {
// loop from the lowest pin to the highest:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);

// loop from the highest pin to the lowest:


/*
Calibration // record the maximum sensor value
if (sensorValue > sensorMax) {
Demonstrates one technique for calibrating sensor input. sensorMax = sensorValue;
The }
sensor readings during the first five seconds of the sketch
execution define the minimum and maximum of expected // record the minimum sensor value
values if (sensorValue < sensorMin) {
attached to the sensor pin. sensorMin = sensorValue;
}
The sensor minimum and maximum initial values may seem }
backwards.
Initially, you set the minimum high and listen for anything // signal the end of the calibration period
lower, saving it as the new minimum. Likewise, you set the digitalWrite(13, LOW);
maximum low and listen for anything higher as the new }
maximum.
void loop() {
The circuit: // read the sensor:
* Analog sensor (potentiometer will do) attached to analog sensorValue = analogRead(sensorPin);
input 0
* LED attached from digital pin 9 to ground // apply the calibration to the sensor reading
sensorValue = map(sensorValue, sensorMin, sensorMax, 0,
created 29 Oct 2008 255);
By David A Mellis
modified 30 Aug 2011 // in case the sensor value is outside the range seen during
By Tom Igoe calibration
sensorValue = constrain(sensorValue, 0, 255);
http://www.arduino.cc/en/Tutorial/Calibration
// fade the LED using the calibrated value:
This example code is in the public domain. analogWrite(ledPin, sensorValue);
}
*/

// These constants won't change:


const int sensorPin = A0; // pin that the sensor is attached
to
const int ledPin = 9; // pin that the LED is attached to

// variables:
int sensorValue = 0; // the sensor value
int sensorMin = 1023; // minimum sensor value
int sensorMax = 0; // maximum sensor value

void setup() {
// turn on LED to signal the start of the calibration period:
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);

// calibrate during the first five seconds


while (millis() < 5000) {
sensorValue = analogRead(sensorPin);
/*
Mega analogWrite() test

This sketch fades LEDs up and down one at a time on digital


pins 2 through 13.
This sketch was written for the Arduino Mega, and will not
work on previous boards.

The circuit:
* LEDs attached from pins 2 through 13 to ground.

created 8 Feb 2009


by Tom Igoe

This example code is in the public domain.

*/
// These constants won't change. They're used to give
names
// to the pins used:
const int lowestPin = 2;
const int highestPin = 13;

void setup() {
// set pins 2 through 13 as outputs:
for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++)
{
pinMode(thisPin, OUTPUT);
}
}

void loop() {
// iterate over the pins:
for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++)
{
// fade the LED on thisPin from off to brightest:
for (int brightness = 0; brightness < 255; brightness++) {
analogWrite(thisPin, brightness);
delay(2);
}
// fade the LED on thisPin from brithstest to off:
for (int brightness = 255; brightness >= 0; brightness--) {
analogWrite(thisPin, brightness);
delay(2);
}
// pause between LEDs:
delay(100);
}
}
/* // turn LED on:
Button digitalWrite(ledPin, HIGH);
} else {
Turns on and off a light emitting diode(LED) connected to // turn LED off:
digital digitalWrite(ledPin, LOW);
pin 13, when pressing a pushbutton attached to pin 2. }
}

The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground

* Note: on most Arduinos there is already an LED on the


board
attached to pin 13.

created 2005
by DojoDave <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/Button
*/

// constants won't change. They're used here to


// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton
pin
const int ledPin = 13; // the number of the LED pin

// variables will change:


int buttonState = 0; // variable for reading the
pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.


// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
/* digitalWrite (10, HIGH);
Amazing Blink digitalWrite (11, HIGH);
digitalWrite (12, HIGH);
June 23, 2017 digitalWrite (13, HIGH);
by: Gabrielle Ailen Beatrize Nepomuceno delay (1000);
STEM 10- Gregorio Zara digitalWrite (6, LOW);
*/ digitalWrite (7, LOW);
digitalWrite (8, LOW);
int led1 = 6; digitalWrite (9, LOW);
int led2 = 7; digitalWrite (10, LOW);
int led3 = 8; digitalWrite (11, LOW);
int led4 = 9; digitalWrite (12, LOW);
int led5 = 10; digitalWrite (13, LOW);
int led6 = 11; delay (1000);
int led7 = 12;
int led8 = 13; digitalWrite (6, HIGH);
digitalWrite (7, HIGH);
void setup() { digitalWrite (8, LOW);
pinMode (6, OUTPUT); digitalWrite (9, LOW);
pinMode (7, OUTPUT); digitalWrite (10, HIGH);
pinMode (8, OUTPUT); digitalWrite (11, HIGH);
pinMode (9, OUTPUT); digitalWrite (12, LOW);
pinMode (10, OUTPUT); digitalWrite (13, LOW);
pinMode (11, OUTPUT); delay (1000);
pinMode (12, OUTPUT); digitalWrite (6, LOW);
pinMode (13, OUTPUT); digitalWrite (7, LOW);
} digitalWrite (8, HIGH);
digitalWrite (9, HIGH);
void loop () { digitalWrite (10, LOW);
digitalWrite (6, HIGH); digitalWrite (11, LOW);
digitalWrite (7, LOW); digitalWrite (12, HIGH);
digitalWrite (8, HIGH); digitalWrite (13, HIGH);
digitalWrite (9, LOW); delay (1000);
digitalWrite (10, HIGH);
digitalWrite (11, LOW);
digitalWrite (12, HIGH); digitalWrite (6, HIGH);
digitalWrite (13, LOW); digitalWrite (7, LOW);
delay (1000); digitalWrite (8, HIGH);
digitalWrite (6, LOW); digitalWrite (9, LOW);
digitalWrite (7, HIGH); digitalWrite (10, HIGH);
digitalWrite (8, LOW); digitalWrite (11, LOW);
digitalWrite (9, HIGH); digitalWrite (12, HIGH);
digitalWrite (10, LOW); digitalWrite (13, LOW);
digitalWrite (11, HIGH); delay (1000);
digitalWrite (12, LOW); digitalWrite (6, LOW);
digitalWrite (13, HIGH); digitalWrite (7, HIGH);
delay (1000); digitalWrite (8, LOW);
digitalWrite (9, HIGH);
digitalWrite (6, HIGH); digitalWrite (10, LOW);
digitalWrite (7, HIGH); digitalWrite (11, HIGH);
digitalWrite (8, HIGH); digitalWrite (12, LOW);
digitalWrite (9, HIGH); digitalWrite (13, HIGH);
delay (1000);

digitalWrite (6, HIGH);


digitalWrite (7, HIGH);
digitalWrite (8, HIGH);
digitalWrite (9, HIGH);
digitalWrite (10, HIGH);
digitalWrite (11, HIGH);
digitalWrite (12, HIGH);
digitalWrite (13, HIGH);
delay (1000);
digitalWrite (6, LOW);
digitalWrite (7, LOW);
digitalWrite (8, LOW);
digitalWrite (9, LOW);
digitalWrite (10, LOW);
digitalWrite (11, LOW);
digitalWrite (12, LOW);
digitalWrite (13, LOW);
delay (1000);

digitalWrite (6, HIGH);


digitalWrite (7, HIGH);
digitalWrite (8, LOW);
digitalWrite (9, LOW);
digitalWrite (10, HIGH);
digitalWrite (11, HIGH);
digitalWrite (12, LOW);
digitalWrite (13, LOW);
delay (1000);
digitalWrite (6, LOW);
digitalWrite (7, LOW);
digitalWrite (8, HIGH);
digitalWrite (9, HIGH);
digitalWrite (10, LOW);
digitalWrite (11, LOW);
digitalWrite (12, HIGH);
digitalWrite (13, HIGH);
delay (1000);
}
///npb void setup() {
/* // set up the LCD's number of columns and rows:
this is code by marlon lcd.begin(16, 2);
enjoy and be happy:) // Print a message to the LCD.
lcd.setCursor(1,0);
/* lcd.print("WALANG POREBER");
LiquidCrystal Library - Hello Marlon }

Demonstrates the use a 16x2 LCD display. The LiquidCrystal void loop() {
library works with all LCD displays that are compatible with // set the cursor to column 0, line 1
the // (note: line 1 is the second row, since counting begins
Hitachi HD44780 driver. There are many of them out there, with 0):
and you lcd.setCursor(2, 1);
can usually tell them by the 16-pin interface. // print the number of seconds since reset:
lcd.print("HEHE");
This sketch prints "Hello Marlon!" 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);
int soundSensorPin=A0; analogWrite(LEDPins[i],intensity[i]);
int soundReading=0; }
int soundThreshold=500; for(int i=0; i<numberOfPins;i++){
int intensity[3]={100,500,1000}; intensity[i]--;
int LEDPins[3] = {3,5,6}; if(intensity[i]<0){
int numberOfPins=3; intensity[i]=0;
int currentPin=0; }
int fadeCounter=0; }
int fadeDelay=50; }
boolean switcher = true; }

void setup(){
pinMode(soundSensorPin, INPUT);
for(int i=0; i<numberOfPins;i++){
pinMode(LEDPins[i],OUTPUT);
}
}

void loop(){
soundReading=analogRead(soundSensorPin);
if(soundReading>soundThreshold){
if(switcher){
aboveThreshold(currentPin);
switcher=true;
}
} else {
if(switcher){
belowThreshold();
switcher=true;
}
}
}

void aboveThreshold(int cPin){


switcher=false;
if(intensity[cPin]<10){
intensity[cPin]=255;
delay(50);
currentPin=currentPin+1;
}

if(currentPin==numberOfPins){
currentPin=0;
}
}

void belowThreshold(){
switcher=false;
fadeCounter++;
if(fadeCounter==fadeDelay){
fadeCounter=0;
for(int i=0; i<numberOfPins;i++){
int ledpin1 = 13; digitalWrite(7,LOW);
int ledpin2 = 12; delay(10);
int ledpin3 = 11; digitalWrite(6,LOW);
int ledpin4 = 10; delay(100);
int ledpin5 = 9;
int ledpin6 = 8; }
int ledpin7 = 7;
int ledpin8 = 6;
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
pinMode(10,OUTPUT);
pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(13,HIGH);
delay(10);
digitalWrite(12,HIGH);
delay(100);
digitalWrite(11,HIGH);
delay(10);
digitalWrite(10,HIGH);
delay(100);
digitalWrite(9,HIGH);
delay(10);
digitalWrite(8,HIGH);
delay(100);
digitalWrite(7,HIGH);
delay(10);
digitalWrite(6,HIGH);
delay(100);

digitalWrite(13,LOW);
delay(10);
digitalWrite(12,LOW);
delay(100);
digitalWrite(11,LOW);
delay(10);
digitalWrite(10,LOW);
delay(100);
digitalWrite(9,LOW);
delay(10);
digitalWrite(8,LOW);
delay(100);

Vous aimerez peut-être aussi