Back to Parent

int speakerPin = D5;

int numTones = 10;
int tones[] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440};
//            mid C  C#   D    D#   E    F    F#   G    G#   A


// Define a pin that we'll place the FSR on
// Remember to add a 10K Ohm pull-down resistor too.
int fsrPin = A0;
int tiltPin = D3;

// Create a variable to hold the FSR reading
int fsrReading = 0;
int tiltstate = 0;

// Define a pin we'll place an LED on
int ledFsr = D0;
int ledTilt = D2;
// Create a variable to store the LED brightness.
int ledBrightness = 0;

//
void setup(){

  // Set up the LED for output
  pinMode(ledFsr, OUTPUT);
  pinMode(ledTilt, OUTPUT);

  pinMode(tiltPin, INPUT);

  // Create a cloud variable of type integer
  // called 'light' mapped to photoCellReading
  Spark.variable("force", &fsrReading, INT);
}

void loop() {

  // Use analogRead to read the photo cell reading
  // This gives us a value from 0 to 4095
  fsrReading = analogRead(fsrPin);

  // Map this value into the PWM range (0-255)
  // and store as the led brightness
  ledBrightness = map(fsrReading, 0, 4095, 0, 255);

  // fade the LED to the desired brightness
  analogWrite(ledFsr, ledBrightness);

  // wait 1/10th of a second and then loop
  //delay(100);


  tiltState = digitalRead(tiltPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (tiltstate == HIGH) {
    // turn LED on:
    for (int i = 0; i < numTones; i++)
  {
    tone(speakerPin, tones[i]);
    delay(100);
  }
  noTone(speakerPin);}

    digitalWrite(ledTilt, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledTilt, LOW);
  }



}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0