Monthly Archives: January 2006
Digital Input controlling Digital output
More generically, it turns on a digital output based on the state of a digital input…. If a digital input on pin 3 is HIGH, the motor turns on. Otherwise it turns off. Continue reading
Servo motor control in Arduino
It moves a servo from its minimum angle to its maximum, in 100 steps. Note: this exam Thanks to Casey Reas for cleaning up the code. Continue reading
MIDI player in Wiring/Arduino
/* MIDI player by Tom Igoe Reads an analog value in on analog channel 0, and if a switch on pin 10 is pressed, plays a note in the middle C octave corresponding to the analog value. Thanks to Ryan Holsopple for getting MIDI out working using serialWrite() Created 19 Jan. 2006 updated */ // The switch is on Arduino pin 10: #define switchPin 10 // Middle C (MIDI note value 60) is the lowest note we’ll play: #define middleC 60 // Indicator LED: #define LEDpin 13 // Variables: char note = 0; // The MIDI note value to be played int AnalogValue = 0; // value from the analog input int lastNotePlayed = 0; // note turned on when you press the switch int lastSwitchState = 0; // state of the switch during previous time through the main loop //Function prototype: void noteOn(char cmd, char data1, char data2); void blink(); void setup() { // set the states of the I/O pins: pinMode(switchPin, INPUT); pinMode(LEDpin, OUTPUT); // Set MIDI baud rate: beginSerial(31250); blink(3); } void loop() { // My potentiometer gave a range from 0 to 1023: AnalogValue = analogRead(0); // convert to a range from 0 to 11: note = AnalogValue / 100; // Check to see that the switch is pressed: if (digitalRead(switchPin) == 1) { // check to see that the switch wasn’t pressed last time // through the main loop: if (lastSwitchState == 0) { // set the note value based on the analog value note = note + middleC; // start a note playing: noteOn(0×90, note, 0×40); // save the note we played, so we can turn it off: lastNotePlayed = note; } else // if the switch is not pressed: // but the switch was pressed last time through the main loop: if (lastSwitchState == 1) { // stop the last note played: noteOn(0×90, lastNotePlayed, 0×00); } } // save the state of the switch for next time // through the main loop: lastSwitchState = switchPin; } // plays a MIDI note. Continue reading
Maxbotix Ultrasonic Sensor
The Maxbotix ultrasonic sensor looks like an interesting model, in that it’s smaller than most ultrasonics, and has a number of different interfaces: serial, PWM, and analog.
Continue reading