Användarverktyg

Webbverktyg


lador:jukebox

JukeBox

Bygg ditt eget Keyboard eller spela med ljuset. Projekten tagna ur 'Arduino Projects Book' (CC-BY-NC-SA 3.0) som medföljer Arduino start kit:et. Så även alla komponenter.

Material

  • 1st Arduino Uno
  • 1st kopplingsplatta
  • 1st USB-kabel
  • 1st USB-minne med programvara
  • 1st fotoresistor
  • 4st tryckknappar/strömbrytare
  • 1st Piezo
  • 3st 10kΩ motstånd
  • 1st 1MΩ motstånd
  • 1st 220Ω motstånd
  • div kopplingskablar

Ljustheremin

Koppla ihop kretsen enligt kopligsschemat, programmera arduino:n och spela med ljuset!

Kopplingsschema

FIXME

Sketch/kod

 
 http://arduino.cc/starterKit
 
 This example code is part of the public domain 
*/

// variable to hold sensor value
int sensorValue;
// variable to calibrate low value
int sensorLow = 1023;
// variable to calibrate high value
int sensorHigh = 0;
// LED pin
const int ledPin = 13;

void setup() {
  // Make the LED pin an output and turn it on
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);

  // calibrate for the first five seconds after program runs
  while (millis() < 5000) {
    // record the maximum sensor value
    sensorValue = analogRead(A0);
    if (sensorValue > sensorHigh) {
      sensorHigh = sensorValue;
    }
    // record the minimum sensor value
    if (sensorValue < sensorLow) {
      sensorLow = sensorValue;
    }
  }
  // turn the LED off, signaling the end of the calibration period
  digitalWrite(ledPin, LOW);
}

void loop() {
  //read the input from A0 and store it in a variable
  sensorValue = analogRead(A0);

  // map the sensor values to a wide range of pitches
  int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000);

  // play the tone for 20 ms on pin 8
  tone(8, pitch, 20);

  // wait for a moment
  delay(10);
}

Keyboard

Med detta keyboard kan du spela C, D, E & F. Vill du spela andra toner? Googla deras frekvenser och ändra i koden.

Kopplingsschema

FIXME

Sketch/Kod

/ create an array of notes
// the numbers below correspond to
// the frequencies of middle C, D, E, and F
int notes[] = {262, 294, 330, 349};

void setup() {
//start serial communication
Serial.begin(9600);
}

void loop() {
// create a local variable to hold the input on pin A0
 int keyVal = analogRead(A0);
// send the value from A0 to the Serial Monitor
 Serial.println(keyVal);

// play the note corresponding to each value on A0
 if(keyVal == 1023){
// play the first frequency in the array on pin 8
  tone(8, notes[0]);
 }
 else if(keyVal >= 990 && keyVal <= 1010){
// play the second frequency in the array on pin 8
  tone(8, notes[1]);
 }
 else if(keyVal >= 505 && keyVal <= 515){
// play the third frequency in the array on pin 8
  tone(8, notes[2]);
  }
 else if(keyVal >= 5 && keyVal <= 10){
// play the fourth frequency in the array on pin 8
  tone(8, notes[3]);
  }
 else{
// if the value is out of range, play no tone
  noTone(8);
 }
}
lador/jukebox.txt · Senast uppdaterad: 2016/01/29 06:46 av joehill