ARDUINO PROGRAMMING by xiuliliaofz

VIEWS: 32 PAGES: 7

									ARDUINO PROGRAMMING
Working with the Arduino microcontroller
                 Arduino Programming
                            Digital I/O (2 – 13)   Serial Transfer (0 -1)


USB (Data & Power)




 Power Source                                                      Reset
   Jumper

Alternate Power (9V)




                        5V / 9V / GND (x2) Analog Input (0 – 5)
Compile Upload to controller   Serial Monitor
                                                      Arduino
                                                        IDE
                                                      Window
                                                Code Editor




                                                Serial Data Transfer Output
             Arduino Code Basics
Arduino programs run on two basic methods:

     void setup() {

         //setup serial and pinout configuration

     }
     void run() {

         //Read and write to serial
         //Read and write to I/O

     }
          Arduino Code Basics
• Data is transferred to and from peripherals
  (LED’s, motors, actuators etc) via digital I/O

• Data is transferred to and from the computer
  via Serial I/O (Either USB or Bluetooth to talk
  to Flash in our case)

• Both of these channels need to be initialized
  in the setup() method
    Arduino Code Basics
int ledPin = 13;

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

}
void run() {

    int activeLED = Serial.read();
    if(activeLED == 3){
         digitalWrite(ledPin, HIGH);
         delay(500);
    }
    Serial.println(activeLED);
}


    http://www.arduino.cc/en/Reference/HomePage
Arduino Code – Control Servo

   Int servoPin = 2;

   void setup() {

       pinMode(servoPin, OUTPUT);

   }
   void run() {

       int activeLED = Serial.read();
       if(activeLED == 3){
            digitalWrite(ledPin, HIGH);
       }
       Serial.println(activeLED);
   }

								
To top