顯示具有 Arduino 標籤的文章。 顯示所有文章
顯示具有 Arduino 標籤的文章。 顯示所有文章

2017年6月24日 星期六

[Arduino][ncurses-5.9] Compile ncurses-5.9 by using gcc-5

Download package
ncurses-5.9.tar.gz


Decompress package, and configure it.
./configure –prefix=/opt –with-shared –without-normal –without-debug –without-cxx-binding CC=/usr/bin/gcc-5


Patch into current file.
./script/build failure with GCC 5.1.0


Create patch file
modules/ncurses - fix complation on gcc 5.1


Save following file into a.patch
--- a/ncurses/base/MKlib_gen.sh
+++ b/ncurses/base/MKlib_gen.sh
@@ -474,11 +474,22 @@ sed -n -f $ED1 \
    -e 's/gen_$//' \
    -e 's/  / /g' >>$TMP

+cat >$ED1 <<EOF
+s/  / /g
+s/^ //
+s/ $//
+s/P_NCURSES_BOOL/NCURSES_BOOL/g
+EOF
+
+# A patch discussed here:
+#  https://gcc.gnu.org/ml/gcc-patches/2014-06/msg02185.html
+# introduces spurious #line markers.  Work around that by ignoring the system's
+# attempt to define "bool" and using our own symbol here.
+sed -e 's/bool/P_NCURSES_BOOL/g' $TMP > $ED2
+cat $ED2 >$TMP
+
 $preprocessor $TMP 2>/dev/null \
-| sed \
-   -e 's/  / /g' \
-   -e 's/^ //' \
-   -e 's/_Bool/NCURSES_BOOL/g' \
+| sed -f $ED1 \
 | $AWK -f $AW2 \
 | sed -f $ED3 \
 | sed \
Under the folder of ncurses-5.9
patch -p1 < a.patch


Start to compile and install
make && make install


link file into /usr/lib/
sudo ln -s /opt/lib/libncurses.so /usr/lib/libncurses.so.5
sudo ln -s /opt/lib/libncurses.so /usr/lib/libtinfo.so.5


Reference:

2016年7月22日 星期五

[Arduino][Gentoo] libtinfo.so.5: cannot open shared object file

Q:
/home/happy/Downloads/arduino-1.6.9/hardware/tools/avr/bin/avrdude: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

A:
emerge sys-libs/ncurses
cd /lib
sudo ln -s libncurses.so.5.7 libtinfo.so.5

Reference:

2016年3月29日 星期二

2016年3月2日 星期三

2016年2月27日 星期六

[Arduino] How to drive SG90 by using arduino




Connecting

Pin Brown = connect to Arduino - / GND
Pin Orange = connect to arduino +5V
Pin Yellow = in this example connect to Arduino Digital port 9

Code

#include <Servo.h> 

Servo myservo; // create servo object to control a servo 
// a maximum of eight servo objects can be created 

int pos = 0; // variable to store the servo position 

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

void loop() 
{ 
  for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees 
  { // in steps of 1 degree 
    myservo.write(pos); // tell servo to go to position in variable 'pos' 
    delay(15); // waits 15ms for the servo to reach the position 
  } 
  for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees 
  { 
    myservo.write(pos); // tell servo to go to position in variable 'pos' 
    delay(15); // waits 15ms for the servo to reach the position 
  } 
}

Reference:

[Arduino] avrdude - libncurses.so.5: cannot open shared object file: No such file or directory


Q:
avrdude: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

A:
  1. Install package
    pacman -S --noconfirm avrdude

  2. rm ~/.platformio/packages/tool-avrdude/avrdude
    ln -s /usr/bin/avrdude ~/.platformio/packages/tool-avrdude/avrdude
Reference:

2015年1月12日 星期一

[Latex][Archlinux] latex to compile yzu_thesis_latex_v203 without issue

Archlinux :
pacman -S –noconfirm texlive-most
pacman -S –noconfirm texlive-lang


Ubuntu :
sudo apt-get –yes –force-yes install texlive-xetex
sudo apt-get –yes –force-yes install latex-cjk-all
sudo apt-get –yes –force-yes install texlive
sudo apt-get –yes –force-yes install texlive-publishers


Then latex xxx and bibtex xxx will no problem


Reference:

2014年10月19日 星期日

[Raspberry Pi][Arduino] Raspberry Pi control bar graph LED throught arduino



enter image description here

Study the following two article

1. [Raspberry Pi][Arduino] Raspberry pi connect to arduino by using I2C
2. [Arduino] Using 74HC595 to control bar graph LED

Arduino Code :

#include <Wire.h>
#define SLAVE_ADDRESS 0x04

int number = 0;
int state = 0;
int LED_Num = 0;

//Pin connected to ST_CP of 74HC595
int latchPin = 8;

//Pin connected to SH_CP of 74HC595
int clockPin = 12;

////Pin connected to DS of 74HC595
int dataPin = 11;
double temp;

void setup() {
    Serial.begin(9600); // send and receive at 9600 baud

    //set pins to output so you can control the shift register
    pinMode(latchPin, OUTPUT);
    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, OUTPUT);

    // initialize i2c as slave
    Wire.begin(SLAVE_ADDRESS);

    // define callbacks for i2c communication
    Wire.onReceive(receiveData);
    Wire.onRequest(sendData);
}



void loop() {
    delay(100);
}



// callback for received data

void receiveData(int byteCount){

 while(Wire.available()) {



  number = Wire.read();



  switch (number) {
    case 0:
      LED_Num = number;
      break;

    case 1:
      LED_Num = number;
      break;

    case 2:
      LED_Num = number;
      break;

    case 3:
      LED_Num = number;
      break;

    case 4:
      LED_Num = number;
      break;

    case 5:
      LED_Num = number;
      break;

    case 6:
      LED_Num = number;
      break;

    case 7:
      LED_Num = number;
      break;

    case 8:
      LED_Num = number;
      break;

    case 9:
      LED_Num = number;
      break;

    case 10:
      LED_Num = number;
      break;

    default:
      // if nothing else matches, do the default
      // default is optional
      break;
  }

    // digitalWrite(latchPin, LOW);
    // shift out the bits:
    // shiftOut(dataPin, clockPin, MSBFIRST, (1 << LED_Num) - 1);
    // take the latch pin high so the LEDs will light up:
    // digitalWrite(latchPin, HIGH);


    int numberToDisplay  = 1 << (LED_Num - 1);
    byte high_Byte = highByte(numberToDisplay);
    byte low_Byte = lowByte(numberToDisplay);

    /* Debug message  Crtl+Shift+M */
    Serial.print("The binary of high_Byte is ");
    Serial.println(high_Byte, BIN);
    Serial.print("The binary of  low_Byte is ");
    Serial.println(low_Byte, BIN);

    // 送資料前要先把 latchPin 拉成低電位
    digitalWrite(latchPin, LOW);

    // 先送高位元組 (Hight Byte), 給離 Arduino 較遠的那顆 74HC595
    shiftOut(dataPin, clockPin, MSBFIRST, high_Byte);

    // 再送低位元組 (Low Byte), 給離 Arduino 較近的那顆 74HC595
    shiftOut(dataPin, clockPin, MSBFIRST, low_Byte);

    // 送完資料後要把 latchPin 拉回成高電位
    digitalWrite(latchPin, HIGH);
 }
}

// callback for sending data
void sendData(){
 Wire.write(number);

}

Raspberry Pi Part:

#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>

// The PiWeather board i2c address
#define ADDRESS 0x04

// The I2C bus: This is for V2 pi's. For V1 Model B you need i2c-0
static const char *devName = "/dev/i2c-1";

int main(int argc, char** argv) {

  if (argc == 1) {
    printf("Supply one or more commands to send to the Arduino\n");
    exit(1);
  }

  printf("I2C: Connecting\n");
  int file;

  if ((file = open(devName, O_RDWR)) < 0) {
    fprintf(stderr, "I2C: Failed to access %d\n", devName);
    exit(1);
  }

  printf("I2C: acquiring buss to 0x%x\n", ADDRESS);

  if (ioctl(file, I2C_SLAVE, ADDRESS) < 0) {
    fprintf(stderr, "I2C: Failed to acquire bus access/talk to slave 0x%x\n", ADDRESS);
    exit(1);
  }

  int arg;

  for (arg = 1; arg < argc; arg++) {
    int val;
    unsigned char cmd[16];

    if (0 == sscanf(argv[arg], "%d", &val)) {
      fprintf(stderr, "Invalid parameter %d \"%s\"\n", arg, argv[arg]);
      exit(1);
    }

    printf("Sending %d\n", val);

    cmd[0] = val;
    if (write(file, cmd, 1) == 1) {

      // As we are not talking to direct hardware but a microcontroller we
      // need to wait a short while so that it can respond.
      //
      // 1ms seems to be enough but it depends on what workload it has
      usleep(10000);

      char buf[1];
      if (read(file, buf, 1) == 1) {
    int temp = (int) buf[0];

    printf("Received %d\n", temp);
      }
    }

    // Now wait else you could crash the arduino by sending requests too fast
    usleep(10000);
  }

  close(file);
  return (EXIT_SUCCESS);
}


Execute :

pi@raspberrypi ~/test $ ./raspberry_to_arduino 1
I2C: Connecting
I2C: acquiring buss to 0x4
Sending 1
Received 1

Reference :
1. switch / case statements
2. Arduino 筆記 – Lab12 使用兩顆 74HC595 和三支腳位控制 16 顆 LED
3. 4.1Sending Debug Information from Arduino to Your Computer
4. Arduino Tutorial #3 - Shift Registers (74HC595)




[Arduino] Using 74HC595 to control bar graph LED




Final production - Second Try

enter image description here

First Try

enter image description here

This side of bar graph LED is negative pin.

enter image description here

74HC595 IC

enter image description here

Reference Serial to Parallel Shifting-Out with a 74HC595 will find out the following circuit diagram.

enter image description here

Using the following code will let the bar graph LED blinking.



 




/*
Shift Register Example
Turning on the outputs of a 74HC595 using an array

Hardware:
* 74HC595 shift register
* LEDs attached to each of the outputs of the shift register

*/

//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;

//holders for infromation you're going to pass to shifting function
byte data;
byte dataArray[10];

void setup() {
//set pins to output because they are addressed in the main loop
pinMode
(latchPin, OUTPUT);
Serial.begin(9600);

//Arduino doesn't seem to have a way to write binary straight into the code
//so these values are in HEX. Decimal would have been fine, too.
dataArray
[0] = 0xFF; //11111111
dataArray
[1] = 0xFE; //11111110
dataArray
[2] = 0xFC; //11111100
dataArray
[3] = 0xF8; //11111000
dataArray
[4] = 0xF0; //11110000
dataArray
[5] = 0xE0; //11100000
dataArray
[6] = 0xC0; //11000000
dataArray
[7] = 0x80; //10000000
dataArray
[8] = 0x00; //00000000
dataArray
[9] = 0xE0; //11100000

//function that blinks all the LEDs
//gets passed the number of blinks and the pause time
blinkAll_2Bytes
(2,500);
}

void loop() {

for (int j = 0; j < 10; j++) {
//load the light sequence you want from array
data
= dataArray[j];
//ground latchPin and hold low for as long as you are transmitting
digitalWrite
(latchPin, 0);
//move 'em out
shiftOut
(dataPin, clockPin, data);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite
(latchPin, 1);
delay
(300);
}
}



// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low

//internal function setup
int i=0;
int pinState;
pinMode
(myClockPin, OUTPUT);
pinMode
(myDataPin, OUTPUT);

//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite
(myDataPin, 0);
digitalWrite
(myClockPin, 0);

//for each bit in the byte myDataOut�
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that 000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite
(myClockPin, 0);

//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState
= 1;
}
else {
pinState
= 0;
}

//Sets the pin to HIGH or LOW depending on pinState
digitalWrite
(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite
(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite
(myDataPin, 0);
}

//stop shifting
digitalWrite
(myClockPin, 0);
}


//blinks the whole register based on the number of times you want to
//blink "n" and the pause between them "d"
//starts with a moment of darkness to make sure the first blink
//has its full visual effect.
void blinkAll_2Bytes(int n, int d) {
digitalWrite
(latchPin, 0);
shiftOut
(dataPin, clockPin, 0);
shiftOut
(dataPin, clockPin, 0);
digitalWrite
(latchPin, 1);
delay
(200);
for (int x = 0; x < n; x++) {
digitalWrite
(latchPin, 0);
shiftOut
(dataPin, clockPin, 255);
shiftOut
(dataPin, clockPin, 255);
digitalWrite
(latchPin, 1);
delay
(d);
digitalWrite
(latchPin, 0);
shiftOut
(dataPin, clockPin, 0);
shiftOut
(dataPin, clockPin, 0);
digitalWrite
(latchPin, 1);
delay
(d);
}
}


PCB Board :

I try to make a IC board, but fail. I will find out what happen.

Front :

enter image description here

Back :

enter image description here



Combine together with arduino

enter image description here





enter image description here





Reference:

1. Search IC Specification

2. Serial to Parallel Shifting-Out with a 74HC595

3. 74HC595 Specification




2014年10月14日 星期二

[Raspberry Pi][Arduino] Raspberry pi connect to arduino by using I2C

The architecture about How to connect between Raspberry pi and Arduino.

enter image description here

How to write code and load binary file into arduino
[arduino] Starting arduino

Download following arduino code and compile it.
Arduino Source Code

Download following arduino code and compile it.
Raspberry Pi Source Code

gcc main.c -o main
./main 1
pi@raspberrypi ~/test $ ./a.out 1
I2C: Connecting
I2C: acquiring buss to 0x4
Sending 1
Received 1

Reference:
  1. Arduino 1.0.6
  2. Raspberry Pi and Arduino Connected Using I2C
  3. Connecting an Arduino to a Raspberry PI using I2C
  4. Connect Raspberry Pi to Arduino with I2C Interface
  5. I2C communication between a RPI and a Arduino
  6. DS1621 with Raspberry Pi/ArchLinuxARM
  7. Control your light at home with a Raspberry Pi and Olimex’s MOD-IO2

2013年11月29日 星期五

2013年11月24日 星期日

[ardublock] How to install ardublock into arduino IDE


1. Open arduino

In Arduino IDE, open menu “Arduino” -> “File” -> “Preferences”

2. Download ardublock

3. cd arduino-1.0.5

mkdir ./tools/ArduBlockTool/tool -p

cp ardublock-all.jar under ./tools/ArduBlockTool/tool

4. Open arduino again

Choose “Tools” -> “ArduBlock”

Reference:

2013年11月20日 星期三

2013年6月17日 星期一

[Arduino] Make Full color LED Lamps bright


[Arduino] Make Full color LED Lamps bright





Document :



Spec



This Full color LED Lamps is common anode.



The pin number 1 of Full color LED Lamp connect to Digital pin ~3.( ~3 mean can do fade function)

The pin number 2 of Full color LED Lamp connect to Digital pin ~5.

The pin number 4 of Full color LED Lamp connect to Digital pin ~6.



#########################################################



/*

 Fade

 

 This example shows how to fade an LED on pin 9

 using the analogWrite() function.

 

 This example code is in the public domain.

 */



int led3 =3;           // the pin that the LED is attached to

int led6 = 6;           // the pin that the LED is attached to

int led9 = 9;           // the pin that the LED is attached to

int brightness = 1;    // how bright the LED is

int fadeAmount = 1;    // 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(led3, OUTPUT);

  pinMode(led6, OUTPUT);  

  pinMode(led9, OUTPUT);    

}



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

void loop()  {

  // set the brightness of pin 9:

  analogWrite(led3, brightness );    

  analogWrite(led6, brightness % 10);

  analogWrite(led9, brightness % 20);  

 

  // 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 == 10) {

    fadeAmount = -fadeAmount ;

  }     

  // wait for 30 milliseconds to see the dimming effect    

  delay(30);                            

}

 

[Arduino] Using 74LS48 decoder and 7 -segment to display number


[Arduino] Using 74LS48 decoder and 7 -segment to display number









#################################################

Document :



PDF file 74LS48 Spec



XL-SD105602 - 0.56-inch Single Digit LED 7-Segment Display



According to PDF (74LS48 -- common cathode) and Single Digit LED 7-segment Display.

Connect Output a to LED a. LED a pin location is 7. 74LS48 output a is pin 13.

Connect Output b to LED b. LED b pin location is 6. 74LS48 output b is pin 12.

Connect Output c to LED c. LED c pin location is 4. 74LS48 output c is pin 11.

Connect Output d to LED d. LED d pin location is 2. 74LS48 output d is pin 10.

Connect Output e to LED e. LED e pin location is 1. 74LS48 output e is pin 9.

Connect Output f  to LED f.  LED f pin location is 9. 74LS48 output f is pin 15.

Connect Output g to LED g. LED g pin location is 10. 74LS48 output g is pin 14.



Connect Input A to Arduino Digital pin 2.

Connect Input B to Arduino Digital pin 3.

Connect Input C  to Arduino Digital pin 4.

Connect Input D to Arduino Digital pin 5



Because my Digit LED 7-segment Display is common cathode

So 74LS48 GND is pin 8. Let the pin 8 connect to GND of arduino. That will make the LED blink, other connect to VCC won't blink.





#################################################

/*

  Blink

  Turns on an LED on for one second, then off for one second, repeatedly.

 

  This example code is in the public domain.

 */

 

// Pin 13 has an LED connected on most Arduino boards.

// give it a name:







#define led2 2

#define led3 3

#define led4 4

#define led5 5





// Pins for A B C D E F G, in sequence

const int segs[4] = { led2, led3, led4, led5};





// Segments that make each number

const byte numbers[10] = {0b0000, 0b0001, 0b0010, 0b0011, 0b0100, 0b0101, 0b0110, 0b0111, 0b1000, 0b1001};



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

void setup() {                

  // initialize the digital pin as an output.

  pinMode(led2, OUTPUT);     

  pinMode(led3, OUTPUT);  

  pinMode(led4, OUTPUT);  

  pinMode(led5, OUTPUT);    

}



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

void loop() {

  for ( int i = 1 ; i <= 9 ; i++)

  {

    lightSegments(numbers[0]);  

    NolightSegments(numbers[0]);  

  }



 



}





void lightSegments(byte number) {

  for (int i = 0; i < 4; i++) {

    int bit = bitRead(number, i);

    digitalWrite(segs[i], bit);

  }

}



void NolightSegments(byte number) {

  for (int i = 0; i < 4; i++) {

    digitalWrite(segs[i], LOW);

  }

}



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

//  delay(1000);               // wait for a second

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

//  delay(1000);



 


[Arduino] 4 Digital Number Display

[Arduino] 4 Digital Number Display







// www.TinkerHobby.com

// Natalia Fargasch Norman

// Dual seven-segment LED Display

// Common Anode digit 1 pin 10

// Common Anode digit 2 pin 5



//       CA1 G  F  A  B

//        |  |  |  |  |      -> pins and segments they control

//   ---------    ---------

//   |   A   |    |   A   |

//  F|       |B  F|       |B

//   |---G---|    |---G---|

//  E|       |C  E|       |C

//   |   D   |    |   D   |

//   ---------    ---------

//        |  |  |  |  |      -> pins and segments they control

//        D  DP E  C CA2       



// Segments that make each number when lit:

// 0 => -FEDCBA

// 1 => ----BC-

// 2 => G-ED-BA

// 3 => G--DCBA

// 4 => GF--CB-

// 5 => GF-DC-A

// 6 => GFEDC-A

// 7 => ----CBA

// 8 => GFEDCBA

// 9 => GF-DCBA



// Arduino digital pins used to light up

// corresponding segments on the LED display

#define A 2

#define B 3

#define C 4

#define D 5

#define E 6

#define f 7

#define G 8



// Pins driving common anodes

#define CA1 13

#define CA2 12

#define CA3 11

#define CA4 10



// Pins for A B C D E F G, in sequence

const int segs[7] = { A, B, C, D, E, f, G };



// Segments that make each number

const byte numbers[10] = { 0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001, 0b0010010,

0b0000010, 0b1111000, 0b0000000, 0b0010000 };



void setup() {

  pinMode(A, OUTPUT);

  pinMode(B, OUTPUT);

  pinMode(C, OUTPUT);

  pinMode(D, OUTPUT);

  pinMode(E, OUTPUT);

  pinMode(f, OUTPUT);

  pinMode(G, OUTPUT);

  pinMode(CA1, OUTPUT);

  pinMode(CA2, OUTPUT);

  pinMode(CA3, OUTPUT);

  pinMode(CA4, OUTPUT);  

}



void loop() {

  for (int digit1=0; digit1 < 10; digit1++) {

    for (int digit2=0; digit2 < 10; digit2++) {

      for (int digit3=0; digit3 < 10; digit3++) {

        for (int digit4=0; digit4 < 10; digit4++) {      

            unsigned long startTime = millis();

            for (unsigned long elapsed=0; elapsed < 600; elapsed = millis() - startTime) {

              lightDigit1(numbers[digit1]);

              delay(5);

              lightDigit2(numbers[digit2]);

              delay(5);

              lightDigit3(numbers[digit3]);

              delay(5);

              lightDigit4(numbers[digit4]);

              delay(5);            

         }

        }

      }

    }

  }

}



void lightDigit1(byte number) {

  digitalWrite(CA1, LOW);

  digitalWrite(CA2, LOW);

  digitalWrite(CA3, LOW);

  digitalWrite(CA4, HIGH);

  lightSegments(number);

}



void lightDigit2(byte number) {

  digitalWrite(CA1, LOW);

  digitalWrite(CA2, LOW);

  digitalWrite(CA3, HIGH);

  digitalWrite(CA4, LOW); 

  lightSegments(number);

}



void lightDigit3(byte number) {

  digitalWrite(CA1, LOW);

  digitalWrite(CA2, HIGH);

  digitalWrite(CA3, LOW);

  digitalWrite(CA4, LOW); 

  lightSegments(number);

}



void lightDigit4(byte number) {

  digitalWrite(CA1, HIGH);

  digitalWrite(CA2, LOW);

  digitalWrite(CA3, LOW);

  digitalWrite(CA4, LOW); 

  lightSegments(number);

}





void lightSegments(byte number) {

  for (int i = 0; i < 7; i++) {

    int bit = bitRead(number, i);

    digitalWrite(segs[i], bit);

  }

}

2013年6月15日 星期六

[Arduino] How to make LED blinking


[Arduino] How to make LED blinking



 





/*

  Blink

  Turns on an LED on for one second, then off for one second, repeatedly.

 

  This example code is in the public domain.

 */

 

// Pin 13 has an LED connected on most Arduino boards.



int timer = 50;           // The higher the number, the slower the timing.



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

void setup() {                





    for (int i = 2; i <= 11; i++) {

      // initialize the digital pin as an output.

      pinMode(i, OUTPUT);



  }

    

 

}



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

void loop() {

 

 

    for (int thisPin = 2; thisPin <= 11; thisPin++) {

    // turn the pin on:

    digitalWrite(thisPin, HIGH);  

    delay(timer);                  

    // turn the pin off:

    digitalWrite(thisPin, LOW);

  }

 

    for (int thisPin = 11; thisPin >= 2; thisPin--) {

    // turn the pin on:

    digitalWrite(thisPin, HIGH);  

    delay(timer);                  

    // turn the pin off:

    digitalWrite(thisPin, LOW);

  }

    

 

}



// Reference:

// 1. For Loop (aka The Knight Rider)