Welcome Guest, you are in: Login
Image

FUBAR Labs Hackerspace Wiki

RSS RSS

Navigation





Search the wiki
»

PoweredBy

Arduino Intro

RSS
Modified on Sun, 21 Oct 2012 10:31 AM by Bill French Categorized as Uncategorized

Class Code Document

https://docs.google.com/document/d/1RE77Wflzc8yFOzTKhaQ_DODVMSZutumdsr-ribPci48/edit

Intro

int TempSensor = 2;
int Pot = 4;
int LightSensor = 3;
int RedLED = 7;
int RGBR = 6;
int RGBG = 5;
int RGBB = 3;
int Button = 2;
int OnboardLED = 13;

void setup() {   
  
}

void loop() {

}

Tester

int TempSensor = 2;
int Pot = 4;
int LightSensor = 3;
int RedLED = 7;
int RGBR = 6;
int RGBG = 5;
int RGBB = 3;
int Button = 2;
int OnboardLED = 13;

void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(OnboardLED, OUTPUT);

  pinMode(RedLED, OUTPUT);
  digitalWrite(RedLED, HIGH);

  pinMode(Button, INPUT);

  pinMode(RGBR, OUTPUT);     
  pinMode(RGBG, OUTPUT);     
  pinMode(RGBB, OUTPUT);     
  digitalWrite(RGBR, HIGH);
  digitalWrite(RGBG, HIGH);
  digitalWrite(RGBB, HIGH);

  Serial.begin(9600);
}

void loop() {

  if(digitalRead(Button))
  {
    digitalWrite(OnboardLED, HIGH);  //set the LED on 
    digitalWrite(RedLED, LOW);   // set the LED on
    //digitalWrite(RGBR, LOW);   // set the LED on
    digitalWrite(RGBG, LOW);   // set the LED on
    //digitalWrite(RGBB, LOW);   // set the LED on
  }
  delay(500);              // wait for a second
  Serial.print("Temp: ");
  Serial.println(analogRead(TempSensor));
  Serial.print("Light: ");
  Serial.println(analogRead(LightSensor));
  Serial.print("Pot: ");
  Serial.println(analogRead(Pot));

  digitalWrite(OnboardLED, LOW);  //set the LED off
  digitalWrite(RedLED, HIGH);    // set the LED off
  //digitalWrite(RGBR, HIGH);   // set the LED off
  digitalWrite(RGBG, HIGH);   // set the LED off
  //digitalWrite(RGBB, HIGH);   // set the LED off
  delay(500);              // wait for a second
}

Ethernet Example

http://arduino.cc/en/Tutorial/WebServer
#include <SPI.h>
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>

byte mac[] = {  
  0xDE, 0xAD, 0xBE, 0xEF,  0xFE, 0xED };
IPAddress ip(192,168,1, 177);
EthernetServer server(80);

void setup()
{
  Ethernet.begin(mac, ip);
  server.begin();
}

void loop()
{
  EthernetClient client = server.available();
  if (client) {
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if (c == '\n' && currentLineIsBlank) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          //DO STUFF!!
          client.print("Hello, World!!");
          client.print("<br>");

          break;
        }
        if (c == '\n') {
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    delay(1);
    client.stop();
  }
}
  Name Size
- LearningShieldTester.zip 717 B

ScrewTurn Wiki version 3.0.5.600. Some of the icons created by FamFamFam.