Blink

/* Blink Turns on an LED on for one second, then off for one second, repeatedly.

Most Arduinos have an on-board LED you can control. On the Uno and Leonardo, it is attached to digital pin 13. If you're unsure what pin the on-board LED is connected to on your Arduino model, check the documentation at http://arduino.cc

This example code is in the public domain.

modified 8 May 2014 by Scott Fitzgerald */

// the setup function runs once when you press reset or power the board

void setup() {

pinMode(13, OUTPUT); // initialize digital pin 13 as an output.}

// the loop function runs over and over again forevervoid loop() { digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second}

// What pin is the LED connected to?int ledPin = 13; // Contains a built in resistor!

// How much time should the light stay on between delays, in Microseconds (millionths of a second)?/* Big number = more blur, more perceived brightness; Small number = less blur, less perceived brightness */

long onTime = 250;

// What should the minimum delay be in milliseconds (thousandths of a second)?// This sets the bottom delay range of the strobe, as a delay of 0 doesn't actually flash =P// The strobe starts with this as the "fastest" mode, and goes slower from there, adding to the delay

int minDelay = 1; // 1 is the lowest we can actually do without a better delay function

// What should the maximum delay be in milliseconds?// This is the longest time that the biggest potentiometer value will be mapped to, and longest// time between strobe flashes.

int maxDelay = 100;

/******* -----=====^^ EASY STUFF TO MESS WITH ^^=====------ ******/

// Initialize the number to hold our strobe delay. Isn't used till we get to the main looplong strobe_delay = 0;

void setup() {pinMode(ledPin, OUTPUT); // Setup ledPin as an output.}

void loop() { // To make the math easier, we use map(value, fromMin, fromMax, toMin, toMax) to convert the // 0 to 1023 range we get from analogRead, into our strobe delay range of 1 to 100 :D strobe_delay = map(analogRead(analogPin), 0, 1023, minDelay, maxDelay);

digitalWrite(ledPin, HIGH); // Switch the ledPin to HIGH, turn it on! delayMicroseconds(onTime); // Delay while on, for the given onTime. digitalWrite(ledPin, LOW); // Switch the ledPin to LOW, turn if off! delay(strobe_delay); // Delay while off, for given strobeDelay.}

// How long should each note play before reading for a new one (in milliseconds)?int note_duration = 200; // 200ms = 5 notes per second (if constantly changing)

// Which analog pin should we read for the value?int analog_read_pin = 0;

/******* -----=====^^ EASY STUFF TO MESS WITH ^^=====------ ******/

// Divide the number of analog read steps (1024) by the number of notes in the list (16).// We do this calculation here to save processing time within the main loop.int analog_steps_per_note = (analog_read_number_of_steps / number_of_notes);

// Initialize the number to hold our note index.. isn't used till we get to the main loopint note_index = 0;

void setup() { // Code to run at startup.. none yet.}

void loop() { // Read the wobbly value from the analog_read_pin // then divide it by the number of steps per note to get a number from 0 to 15 note_index = analogRead(analog_read_pin) / analog_steps_per_note;

// Play the note from the given note_index tone(speaker_pin, notes[note_index]);