F39Ft


Script examples for Arduino UNO
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Freud was, God bless him, essentially a confidence man.
    He didn't invent a cure. He invented a disease.

    Phil Spector, 2013, 00:39:45

-[Blink 13]------------------------------------------------------------

  void setup() {
    pinMode(13, OUTPUT);
  }

  void loop() {
    digitalWrite(13, HIGH);
    delay(1000);
    digitalWrite(13, LOW);
    delay(1000);
  }

-[Toggle Switch / UnoArduSim Slideswitch]------------------------------

  // +V  o----o   o----o GND
  //           \
  //     SW8    o--/\/\/-->

  void setup() {
    pinMode(9, OUTPUT);
    pinMode(8, INPUT);
  }

  void loop() {
    digitalWrite(9, digitalRead(8));
  }

-[LCD shield test]-----------------------------------------------------

  #include <LiquidCrystal.h>

  LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

  void setup() {
    lcd.begin(16, 2); // LCD 16x2

    // Print a message to the LCD.
    lcd.setCursor(0,0);
    lcd.print("LCD Key Shield");
    lcd.setCursor(0,1);
    lcd.print("Press Key:");
  }

  void loop() {
    int x;
    x = analogRead (0);
    lcd.setCursor(10,1);
    if (x < 60) {
      lcd.print ("Right ");
    }
    else if (x < 200) {
      lcd.print ("Up    ");
    }
    else if (x < 400){
      lcd.print ("Down  ");
    }
    else if (x < 600){
      lcd.print ("Left  ");
    }
    else if (x < 800){
      lcd.print ("Select");
    }
  }

-[Control from Serial line]--------------------------------------------

  int data = 0;

  void setup()
  {
      pinMode(  8, OUTPUT);
      pinMode(  9, OUTPUT);
      pinMode( 10, OUTPUT);
      pinMode( 11, OUTPUT);
      pinMode( 12, OUTPUT);
      pinMode( 13, OUTPUT);

      Serial.begin(9600);
  }

  void loop()
  {
      while (Serial.available() == 0) {}
      data = Serial.read();
      Serial.write(data);

      if ( data == 'a' ) digitalWrite(  8, HIGH);
      if ( data == 'b' ) digitalWrite(  8, LOW);

      if ( data == 'c' ) digitalWrite(  9, HIGH);
      if ( data == 'd' ) digitalWrite(  9, LOW);

      if ( data == 'e' ) digitalWrite( 10, HIGH);
      if ( data == 'f' ) digitalWrite( 10, LOW);

      if ( data == 'g' ) digitalWrite( 11, HIGH);
      if ( data == 'h' ) digitalWrite( 11, LOW);

      if ( data == 'i' ) digitalWrite( 12, HIGH);
      if ( data == 'j' ) digitalWrite( 12, LOW);

      if ( data == 'k' ) digitalWrite( 13, HIGH);
      if ( data == 'l' ) digitalWrite( 13, LOW);
  }
