Arduino

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

void loop(){
  digitalWrite(LED_PIN, HIGH);
  delay(500);
  digitalWrite(LED_PIN, LOW);
  delay(500);
}

ハードウェアの制御

#define LED_PIN 9

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

void loop(){
  int i;
  for(i=0; i<256; i++){
  analogWrite(LED_PIN, i);
  delay(10);
  }
}

音声制御

#define LED_SPK 9

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

void loop(){
  int i;
  for(i=0; i<256; i++){
  tone(SPK_PIN, i*10, 20);
  delay(10);
  }
}

タクトスイッチ

#define LED_PIN 13
#define BUTTON 2

void setup(){
  pinMode(LED_PIN, OUTPUT);
  pinMode(BUTTON, INPUT);
}

void loop(){
  if (digitalRead(BUTTON) == HIGH){
    digitalWrite(LED_PIN, HIGH);
  } else {
    digitalWrite(LED_PIN, LOW)
  }
}

Cdsセル

#define SENSOR 0

void setup(){
  pinMode(SENSOR, INPUT);
  Serial.begin(9600);
}

void loop(){
  int i;
  i = analogRead(SENSOR);
  Serial.print(i, DEC);
  Serial.print("\n");
  delay(1000);
}