mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Committing individual examples instead of one .zip
This commit is contained in:
86
build/shared/dist/examples/leds/knight_rider/knight_rider_1/knight_rider_1.pde
vendored
Normal file
86
build/shared/dist/examples/leds/knight_rider/knight_rider_1/knight_rider_1.pde
vendored
Normal file
@ -0,0 +1,86 @@
|
||||
/* Knight Rider 1
|
||||
* --------------
|
||||
*
|
||||
* Knight Rider is an AI car that showed up in the TV series from
|
||||
* the 80's with David Hasselhoff. The car had plenty of LED effects.
|
||||
*
|
||||
* Basically this is an extension of Blink_LED. This program handles
|
||||
* 6 LEDs connected to pins 2 to 7. This is the first of a series of
|
||||
* three examples useful to understand the for(;;) loop
|
||||
*
|
||||
* Picture at:
|
||||
* http://arduino.berlios.de/index.php/Tutorial/KnightRider
|
||||
*
|
||||
* (cleft) 2005 K3, Malmo University
|
||||
* @author: David Cuartielles
|
||||
* @hardware: David Cuartielles, Aaron Hallborg
|
||||
*/
|
||||
|
||||
int pin2 = 2;
|
||||
int pin3 = 3;
|
||||
int pin4 = 4;
|
||||
int pin5 = 5;
|
||||
int pin6 = 6;
|
||||
int pin7 = 7;
|
||||
int timer = 100;
|
||||
|
||||
void setup(){
|
||||
pinMode(pin2, OUTPUT);
|
||||
pinMode(pin3, OUTPUT);
|
||||
pinMode(pin4, OUTPUT);
|
||||
pinMode(pin5, OUTPUT);
|
||||
pinMode(pin6, OUTPUT);
|
||||
pinMode(pin7, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
digitalWrite(pin2, HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pin2, LOW);
|
||||
delay(timer);
|
||||
|
||||
digitalWrite(pin3, HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pin3, LOW);
|
||||
delay(timer);
|
||||
|
||||
digitalWrite(pin4, HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pin4, LOW);
|
||||
delay(timer);
|
||||
|
||||
digitalWrite(pin5, HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pin5, LOW);
|
||||
delay(timer);
|
||||
|
||||
digitalWrite(pin6, HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pin6, LOW);
|
||||
delay(timer);
|
||||
|
||||
digitalWrite(pin7, HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pin7, LOW);
|
||||
delay(timer);
|
||||
|
||||
digitalWrite(pin6, HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pin6, LOW);
|
||||
delay(timer);
|
||||
|
||||
digitalWrite(pin5, HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pin5, LOW);
|
||||
delay(timer);
|
||||
|
||||
digitalWrite(pin4, HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pin4, LOW);
|
||||
delay(timer);
|
||||
|
||||
digitalWrite(pin3, HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pin3, LOW);
|
||||
delay(timer);
|
||||
}
|
46
build/shared/dist/examples/leds/knight_rider/knight_rider_2/knight_rider_2.pde
vendored
Normal file
46
build/shared/dist/examples/leds/knight_rider/knight_rider_2/knight_rider_2.pde
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
/* Knight Rider 2
|
||||
* --------------
|
||||
*
|
||||
* Knight Rider is an AI car that showed up in the TV series from
|
||||
* the 80's with David Hasselhoff. The car had plenty of LED effects.
|
||||
*
|
||||
* Basically this is an extension of Blink_LED. This program handles
|
||||
* 6 LEDs connected to pins 2 to 7. This is the second of a series of
|
||||
* three examples useful to understand the for(;;) loop
|
||||
*
|
||||
* In this example we declare an array with the pin numbers we use as inputs,
|
||||
* then we browse the array up and down to turn the different pins on/off
|
||||
*
|
||||
* Picture at:
|
||||
* http://arduino.berlios.de/index.php/Tutorial/KnightRider
|
||||
*
|
||||
* (cleft) 2005 K3, Malmo University
|
||||
* @author: David Cuartielles
|
||||
* @hardware: David Cuartielles, Aaron Hallborg
|
||||
*/
|
||||
|
||||
int pinArray[] = {2, 3, 4, 5, 6, 7};
|
||||
int count = 0;
|
||||
int timer = 100;
|
||||
|
||||
void setup(){
|
||||
// we make all the declarations at once
|
||||
for (count=0;count<6;count++) {
|
||||
pinMode(pinArray[count], OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (count=0;count<6;count++) {
|
||||
digitalWrite(pinArray[count], HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pinArray[count], LOW);
|
||||
delay(timer);
|
||||
}
|
||||
for (count=5;count>=0;count--) {
|
||||
digitalWrite(pinArray[count], HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pinArray[count], LOW);
|
||||
delay(timer);
|
||||
}
|
||||
}
|
51
build/shared/dist/examples/leds/knight_rider/knight_rider_3/knight_rider_3.pde
vendored
Normal file
51
build/shared/dist/examples/leds/knight_rider/knight_rider_3/knight_rider_3.pde
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
/* Knight Rider 3
|
||||
* --------------
|
||||
*
|
||||
* Knight Rider is an AI car that showed up in the TV series from
|
||||
* the 80's with David Hasselhoff. The car had plenty of LED effects.
|
||||
*
|
||||
* Basically this is an extension of Blink_LED. This program handles
|
||||
* 6 LEDs connected to pins 2 to 7. This is the third of a series of
|
||||
* three examples useful to understand the for(;;) loop
|
||||
*
|
||||
* In this example we declare an array with the pin numbers we use as inputs,
|
||||
* then we browse the array up and down to turn the different pins on/off
|
||||
*
|
||||
* This example concentrates in making the visuals fluid.
|
||||
*
|
||||
* Picture at:
|
||||
* http://arduino.berlios.de/index.php/Tutorial/KnightRider
|
||||
*
|
||||
* (cleft) 2005 K3, Malmo University
|
||||
* @author: David Cuartielles
|
||||
* @hardware: David Cuartielles, Aaron Hallborg
|
||||
*/
|
||||
|
||||
int pinArray[] = {2, 3, 4, 5, 6, 7};
|
||||
int count = 0;
|
||||
int timer = 30;
|
||||
|
||||
void setup(){
|
||||
for (count=0;count<6;count++) {
|
||||
pinMode(pinArray[count], OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (count=0;count<5;count++) {
|
||||
digitalWrite(pinArray[count], HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pinArray[count + 1], HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pinArray[count], LOW);
|
||||
delay(timer*2);
|
||||
}
|
||||
for (count=5;count>0;count--) {
|
||||
digitalWrite(pinArray[count], HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pinArray[count - 1], HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pinArray[count], LOW);
|
||||
delay(timer*2);
|
||||
}
|
||||
}
|
194
build/shared/dist/examples/leds/led_drivers/max7219_v1/max7219_v1.pde
vendored
Normal file
194
build/shared/dist/examples/leds/led_drivers/max7219_v1/max7219_v1.pde
vendored
Normal file
@ -0,0 +1,194 @@
|
||||
int serialVal = 0;
|
||||
int value = 0;
|
||||
int i = 0;
|
||||
boolean reading = false;
|
||||
boolean writing = false;
|
||||
int times = 0;
|
||||
int serialBuff[7];
|
||||
|
||||
// define wiring pins
|
||||
byte pin_max7219_clock = 4;
|
||||
byte pin_max7219_load = 2;
|
||||
byte pin_max7219_dataIn = 3;
|
||||
|
||||
// specify wiring pin i/o directions
|
||||
void setPinModes()
|
||||
{
|
||||
pinMode(pin_max7219_dataIn, OUTPUT);
|
||||
pinMode(pin_max7219_clock, OUTPUT);
|
||||
pinMode(pin_max7219_load, OUTPUT);
|
||||
}
|
||||
|
||||
// define max7219 registers
|
||||
byte max7219_reg_noop = 0x00;
|
||||
byte max7219_reg_digit0 = 0x01;
|
||||
byte max7219_reg_digit1 = 0x02;
|
||||
byte max7219_reg_digit2 = 0x03;
|
||||
byte max7219_reg_digit3 = 0x04;
|
||||
byte max7219_reg_digit4 = 0x05;
|
||||
byte max7219_reg_digit5 = 0x06;
|
||||
byte max7219_reg_digit6 = 0x07;
|
||||
byte max7219_reg_digit7 = 0x08;
|
||||
byte max7219_reg_decodeMode = 0x09;
|
||||
byte max7219_reg_intensity = 0x0a;
|
||||
byte max7219_reg_scanLimit = 0x0b;
|
||||
byte max7219_reg_shutdown = 0x0c;
|
||||
byte max7219_reg_displayTest = 0x0f;
|
||||
|
||||
// define max7219 as rows and cols (for nexus 8x8 displays)
|
||||
byte max7219_row0 = 0x01;
|
||||
byte max7219_row1 = 0x02;
|
||||
byte max7219_row2 = 0x03;
|
||||
byte max7219_row3 = 0x04;
|
||||
byte max7219_row4 = 0x05;
|
||||
byte max7219_row5 = 0x06;
|
||||
byte max7219_row6 = 0x07;
|
||||
byte max7219_row7 = 0x08;
|
||||
byte max7219_col0 = 0x80;
|
||||
byte max7219_col1 = 0x01;
|
||||
byte max7219_col2 = 0x02;
|
||||
byte max7219_col3 = 0x04;
|
||||
byte max7219_col4 = 0x08;
|
||||
byte max7219_col5 = 0x10;
|
||||
byte max7219_col6 = 0x20;
|
||||
byte max7219_col7 = 0x40;
|
||||
|
||||
|
||||
// function to control max7219 data line
|
||||
void max7219_setData(boolean value)
|
||||
{
|
||||
digitalWrite(pin_max7219_dataIn, value);
|
||||
}
|
||||
|
||||
// function to control max7219 clock line
|
||||
void max7219_setClock(boolean value)
|
||||
{
|
||||
digitalWrite(pin_max7219_clock, value);
|
||||
}
|
||||
|
||||
// function to control max7219 load line
|
||||
void max7219_setLoad(boolean value)
|
||||
{
|
||||
digitalWrite(pin_max7219_load, value);
|
||||
}
|
||||
|
||||
// function that puts a byte of data to the max7219
|
||||
void max7219_putByte(byte data)
|
||||
{
|
||||
byte i = 8;
|
||||
byte mask;
|
||||
while(i > 0) {
|
||||
mask = 0x01 << (i - 1); // get bitmask
|
||||
max7219_setClock(LOW); // tick
|
||||
if (data & mask){ // choose bit
|
||||
max7219_setData(HIGH); // send 1
|
||||
}else{
|
||||
max7219_setData(LOW); // send 0
|
||||
}
|
||||
max7219_setClock(HIGH); // tock
|
||||
--i; // move to lesser bit
|
||||
}
|
||||
}
|
||||
|
||||
// function that puts a byte of data into a max7219 register
|
||||
void max7219_put(byte reg, byte data)
|
||||
{
|
||||
max7219_setLoad(HIGH); // begin
|
||||
max7219_putByte(reg); // specify register
|
||||
max7219_putByte(data); // put data
|
||||
max7219_setLoad(LOW); // latch in data
|
||||
max7219_setLoad(HIGH); // end
|
||||
}
|
||||
|
||||
// function that sets brightness of the max7219
|
||||
void max7219_setIntensity(byte intensity)
|
||||
{
|
||||
// range: 0x00 to 0x0f
|
||||
max7219_put(max7219_reg_intensity, intensity & 0x0f);
|
||||
}
|
||||
////////////////////////////////////////////
|
||||
// function that sets the same value for all registers of the max7219
|
||||
|
||||
void max7219_all(byte value)
|
||||
{
|
||||
max7219_put(0x01, value);
|
||||
max7219_put(0x02, value);
|
||||
max7219_put(0x03, value);
|
||||
max7219_put(0x04, value);
|
||||
max7219_put(0x05, value);
|
||||
max7219_put(0x06, value);
|
||||
max7219_put(0x07, value);
|
||||
max7219_put(0x08, value);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
void printBuff(){
|
||||
for (i=1;i <= 8;i++){
|
||||
max7219_put(0x0+i, serialBuff[i-1]);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////
|
||||
|
||||
void readBuff(){
|
||||
printString("into readbuff method");
|
||||
serialVal = serialRead();
|
||||
if (serialVal != -1){
|
||||
printString("information there");
|
||||
if ((serialVal == 43) && !reading){
|
||||
reading = true;
|
||||
printString("plus");
|
||||
}
|
||||
|
||||
if ((serialVal == 45) && (times == 0 && reading)){
|
||||
writing = true;
|
||||
printString("minus");
|
||||
}
|
||||
|
||||
if (reading && writing){
|
||||
serialBuff[times] = serialVal;
|
||||
times++;
|
||||
}
|
||||
|
||||
if (times >= 7){
|
||||
printString("Print to buff");
|
||||
times = 0;
|
||||
reading = false;
|
||||
writing = false;
|
||||
printBuff();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// function that initializes the max7219 to use a matrix of leds
|
||||
void max7219_init()
|
||||
{
|
||||
max7219_put(max7219_reg_scanLimit, 0x07); // use all 8 columns
|
||||
max7219_put(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
|
||||
max7219_put(max7219_reg_shutdown, 0x01); // not in shutdown mode
|
||||
max7219_put(max7219_reg_displayTest, 0x00); // no display test
|
||||
max7219_all(0x00); // empty registers
|
||||
max7219_setIntensity(0x0f); // set initial brightness to dim
|
||||
}
|
||||
|
||||
|
||||
|
||||
// program initialization routine
|
||||
void setup()
|
||||
{
|
||||
setPinModes();
|
||||
max7219_init();
|
||||
}
|
||||
|
||||
// program loop
|
||||
void loop()
|
||||
{
|
||||
printString("in the loop");
|
||||
//max7219_all(0x00);
|
||||
//delay(500);
|
||||
readBuff();
|
||||
|
||||
}
|
79
build/shared/dist/examples/leds/led_drivers/shift_out/shift_out.pde
vendored
Normal file
79
build/shared/dist/examples/leds/led_drivers/shift_out/shift_out.pde
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
/* Shift Out
|
||||
* ---------
|
||||
*
|
||||
* This example uses the LED driver 4794 from Philips to drive
|
||||
* 8 LEDs at once. The 4794 is a chip that can be chained so that
|
||||
* we will be able of adding 8 outputs each time you add a new chip
|
||||
*
|
||||
* We use four pins to connect to the chip:
|
||||
*
|
||||
* - data: this one sends the data out to the chip
|
||||
*
|
||||
* - strob: controls the load of data to the chip's output
|
||||
*
|
||||
* - clock: synchronizes the load of data
|
||||
*
|
||||
* - oe: turns the output on/off, we use it to control the luminosity of the LEDs
|
||||
*
|
||||
* Pictures at:
|
||||
* http://arduino.berlios.de/index.php/Tutorial/LEDDriver
|
||||
*
|
||||
* (copyleft) 2005 K3, Malmo University
|
||||
* @author: David Cuartielles, Marcus Hannerstig
|
||||
* @hardware: David Cuartielles, Marcos Yarza
|
||||
* @project: SMEE - Experiential Vehicles
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
int data = 9;
|
||||
int strob = 8;
|
||||
int clock = 10;
|
||||
int oe = 11;
|
||||
int count = 0;
|
||||
int dato = 0; // dato is a varible we use to send data to the LEDs
|
||||
|
||||
void setup()
|
||||
{
|
||||
//beginSerial(9600); // uncomment the serial-related lines to monitor the program's progress
|
||||
pinMode(data, OUTPUT); // declare all the control pins as outputs
|
||||
pinMode(clock, OUTPUT);
|
||||
pinMode(strob, OUTPUT);
|
||||
pinMode(oe, OUTPUT);
|
||||
}
|
||||
|
||||
|
||||
// sends a pulse to the 4794 indicating that
|
||||
// it is time to load data
|
||||
void PulseClock(void) {
|
||||
digitalWrite(clock, LOW);
|
||||
delayMicroseconds(20);
|
||||
digitalWrite(clock, HIGH);
|
||||
delayMicroseconds(50);
|
||||
digitalWrite(clock, LOW);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
dato = 129; // if dato equals 129 the first and last LED will be on
|
||||
|
||||
// go through the "dato" variable and send it bit by bit over the data pin
|
||||
for (count = 0; count < 8; count++) {
|
||||
digitalWrite(data, dato & 01);
|
||||
//serialWrite((dato & 01) + 48);
|
||||
dato>>=1;
|
||||
if (count == 7){
|
||||
digitalWrite(oe, LOW);
|
||||
digitalWrite(strob, HIGH);
|
||||
}
|
||||
PulseClock();
|
||||
digitalWrite(oe, HIGH);
|
||||
}
|
||||
|
||||
delayMicroseconds(20);
|
||||
digitalWrite(strob, LOW);
|
||||
delay(100);
|
||||
|
||||
//printNewline();
|
||||
delay(100); // waits for a second
|
||||
}
|
Reference in New Issue
Block a user