SlideShare a Scribd company logo
@neilmendoza
Musical Machines and Flapping Phones
!
Neil Mendoza
@neilmendoza
Who are you?
@neilmendoza
@neilmendoza
@neilmendoza
@neilmendoza
@neilmendoza
@neilmendoza
@neilmendoza
What are musical notes?
@neilmendoza
@neilmendoza
Melody: Stepper
@neilmendoza
What is a stepper?
@neilmendoza
Stepper Drivers
@neilmendoza
So many wires…
@neilmendoza
Measure resistance of coils…
@neilmendoza
@neilmendoza
#include <Stepper.h>	
!
// change this to fit the number of steps per revolution	
// for your motor	
const int stepsPerRevolution = 48; 	
!
// initialize the stepper library on the motor shield	
Stepper myStepper(stepsPerRevolution, 12,13); 	
!
// give the motor control pins names:	
const int pwmA = 3;	
const int pwmB = 11;	
const int brakeA = 9;	
const int brakeB = 8;	
const int dirA = 12;	
const int dirB = 13;	
!
void setup()	
{	
	 // set the PWM and brake pins so that the direction pins // can be used to control the motor:	
pinMode(pwmA, OUTPUT);	
pinMode(pwmB, OUTPUT);	
pinMode(brakeA, OUTPUT);	
pinMode(brakeB, OUTPUT);	
digitalWrite(pwmA, HIGH);	
digitalWrite(pwmB, HIGH);	
digitalWrite(brakeA, LOW);	
digitalWrite(brakeB, LOW);	
!
	 // set the motor speed (for multiple steps only):	
myStepper.setSpeed(2);	
}	
!
void loop()	
{	
myStepper.step(48);	
myStepper.step(-48);	
!
delay(2000);	
}
Motor Shield R3 Code
@neilmendoza
Step Direction Driver Code
int dirpin = 2;	
int steppin = 3;	
!
void setup() 	
{	
pinMode(dirpin, OUTPUT);	
pinMode(steppin, OUTPUT);	
}	
!
void loop()	
{	
int i;	
!
digitalWrite(dirpin, LOW); // Set the direction.	
delay(100);	
!
!
for (i = 0; i<4000; i++) // Iterate for 4000 microsteps.	
{	
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the	
digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.	
delayMicroseconds(500); // This delay time is close to top speed for this	
} // particular motor. Any faster the motor stalls.	
!
digitalWrite(dirpin, HIGH); // Change direction.	
delay(100);	
!
!
for (i = 0; i<4000; i++) // Iterate for 4000 microsteps	
{	
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the	
digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.	
delayMicroseconds(500); // This delay time is close to top speed for this	
} // particular motor. Any faster the motor stalls.	
}
@neilmendoza
Controller: MIDI
@neilmendoza
MIDI Circuit
@neilmendoza
Simple MIDI Code
#include <SoftwareSerial.h>	
!
int midiByte0 = -1;	
int midiByte1 = -1;	
int midiByte2 = -1;	
!
#define HI_NIBBLE(b) (((b)>>4) & 0x0F)	
#define LO_NIBBLE(b) ((b) & 0x0F)	
!
#define NOTE_ON_STATUS B1001	
#define NOTE_OFF_STATUS B1000	
#define CC_STATUS B1011	
#define PITCHBEND_STATUS B1110	
!
#define MIDI_BAUD_RATE 31250	
!
const int LED = 13;	
const int MIDI_IN = 8; 	
!
SoftwareSerial midiIn(MIDI_IN, 9); // RX, TX	
!
void setup()	
{ 	
pinMode(LED, OUTPUT); 	
	
midiIn.begin(MIDI_BAUD_RATE);	
}	
!
void loop()	
{	
updateMidi(); 	
}	
!
void noteOn(int channel, int note, int vel)	
{	
digitalWrite(LED, HIGH);	
}	
!
void noteOff(int channel, int note)	
{	
digitalWrite(LED, LOW);	
}
void updateMidi()	
{	
int b = midiIn.read();	
if(b!= -1)	
{ 	
midiByte2 = midiByte1;	
midiByte1 = midiByte0;	
midiByte0 = b;	
	
// only work if we've got a status byte	
// of some sort	
if(!(midiByte2 & B10000000)) return;	
	
int st = HI_NIBBLE(midiByte2);	
int channel = LO_NIBBLE(midiByte2);	
	
// now check to see if we have a midi	
if(st == NOTE_ON_STATUS)	
{	
if(midiByte0 == 0)	
{ 	
// if the volume is zero, it's a note off	
noteOff(channel, midiByte1);	
}	
else	
{	
noteOn(channel, midiByte1, midiByte0); 	
}	
}	
else if(st == NOTE_OFF_STATUS)	
{	
noteOff(channel, midiByte1);	
	 }	
}	
}
@neilmendoza
MIDI to Frequency Code
#include <SoftwareSerial.h>
!
int midiByte0 = -1;
int midiByte1 = -1;
int midiByte2 = -1;
!
#define HI_NIBBLE(b) (((b)>>4) & 0x0F)
#define LO_NIBBLE(b) ((b) & 0x0F)
!
#define NOTE_ON_STATUS B1001
#define NOTE_OFF_STATUS B1000
#define CC_STATUS B1011
#define PITCHBEND_STATUS B1110
!
#define MIDI_BAUD_RATE 31250
!
const unsigned LED_PIN = 13;
const unsigned STEP_PIN = 3;
const unsigned DIR_PIN = 2;
const unsigned MIDI_IN_PIN = 10;
!
SoftwareSerial midiIn(MIDI_IN_PIN, 9); // RX, TX
!
unsigned long halfPeriodMicros = 0;
!
void setup()
{ 
pinMode(LED_PIN, OUTPUT); 
pinMode(STEP_PIN, OUTPUT); 
pinMode(DIR_PIN, OUTPUT); 

digitalWrite(LED_PIN, LOW); 
digitalWrite(STEP_PIN, LOW); 
digitalWrite(DIR_PIN, LOW); 

midiIn.begin(MIDI_BAUD_RATE);
}
!
void loop()
{
if (halfPeriodMicros != 0)
{
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(halfPeriodMicros);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(halfPeriodMicros);
}
}
!
double midiToFrequency(int midiNote)
{
return 440.0 * exp(0.057762265 * (midiNote - 69.0));
}
!
void noteOn(int channel, int midiNote, int vel)
{
halfPeriodMicros = 0.5 * 1000000.0 / midiToFrequency(midiNote);
digitalWrite(LED_PIN, HIGH);
}
!
void noteOff(int channel, int midiNote)
{
halfPeriodMicros = 0;
digitalWrite(LED_PIN, LOW);
}
!
void updateMidi()
{
int b = midiIn.read();
if(b != -1)
{ 
midiByte2 = midiByte1;
midiByte1 = midiByte0;
midiByte0 = b;

// only work if we've got a status byte
// of some sort
if(!(midiByte2 & B10000000)) return;

int st = HI_NIBBLE(midiByte2);
int channel = LO_NIBBLE(midiByte2);

// now check to see if we have a midi
if(st == NOTE_ON_STATUS)
{
if(midiByte0 == 0)
{ 
// if the volume is zero, it's a note off
noteOff(channel, midiByte1);
}
else
{
noteOn(channel, midiByte1, midiByte0); 
}
}
else if(st == NOTE_OFF_STATUS)
{
noteOff(channel, midiByte1);
}
}
}
@neilmendoza
Oscillator Code
#include "Oscillator.h"

unsigned long Oscillator::elapsedMicros = 0;
!
Oscillator::Oscillator(unsigned channel) : channel(channel), periodMicros(0), halfPeriodMicros(0) {}

void Oscillator::noteOn(unsigned channel, unsigned note, unsigned vel)
{
if (this->channel == channel)
{
periodMicros = 1000000.0 / midiToFrequency(note);
halfPeriodMicros = 0.5 * periodMicros;
}
};
!
void Oscillator::noteOff(unsigned channel, unsigned note)
{
if (this->channel == channel)
{
periodMicros = 0;
halfPeriodMicros = 0;
}
};
!
void Oscillator::update()
{
if(periodMicros > 0)
{
unsigned long elapsedPeriodMicros = elapsedMicros % periodMicros;

if(elapsedPeriodMicros > halfPeriodMicros != !wave)
{
// wave form has flipped
wave = !wave;
if (wave) risingEdge();
else fallingEdge();
}
}
};
!
double Oscillator::midiToFrequency(int midiNote)
{
return 440.0 * exp(0.057762265 * (midiNote - 69.0));
}
@neilmendoza
DEMO
@neilmendoza
Percussion: Car Door Lock “Solenoid”
@neilmendoza
Driver Circuit
@neilmendoza
Car Door Lock Code = Blink
int carDoorPin = 10;	
!
// the setup routine runs once when you press reset:	
void setup()	
{ 	
// initialize the digital pin as an output.	
pinMode(carDoorPin, OUTPUT); 	
}	
!
// the loop routine runs over and over again forever:	
void loop()	
{	
digitalWrite(carDoorPin, HIGH); // turn the LED on (HIGH is the voltage level)	
delay(1000); // wait for a second	
digitalWrite(carDoorPin, LOW); // turn the LED off by making the voltage LOW	
delay(1000); // wait for a second	
}
@neilmendoza
DEMO
DEMO
@neilmendoza
Other Coily Things
@neilmendoza
https://github.com/isthisgood/scrapheap-orchestra
@neilmendoza
@neilmendoza@neilmendoza
@neilmendoza
@neilmendoza
@neilmendoza
@neilmendoza
VS
@neilmendoza
@neilmendoza
Many phones still speak the same language
as 1990s modems (AT commands)
ATD0123456789 = Call 0123456789
AT+CHUP = Hang up call
@neilmendoza
Cheap phones that talk serial
Sony Ericsson T237(US)/T230(UK)
@neilmendoza
Phone circuit
@neilmendoza
@neilmendoza
Make a Call
#include <SoftwareSerial.h>	
!
const String PHONE_NUMBER = “07956641707";	
!
SoftwareSerial phone(2, 3);	
!
void setup()	
{	
// start talking to phone over serial	
phone.begin(9600);	
	
// start talking to computer over serial	
// to receive trigger and send debug	
// messages	
Serial.begin(9600);	
}	
!
void loop()	
{	
}	
!
void serialEvent()	
{	
// received a serial event call number	
if (Serial.available())	
{	
// prepare the AT command	
String command("ATD");	
command += PHONE_NUMBER;	
command += ";";	
	
// send it to the phone	
phone.println(command);	
	
// debug message	
Serial.print("Sent AT command: ");	
Serial.println(command);	
	
// clear the serial buffer and wait for	
// next time	
Serial.flush();	
}	
}
@neilmendoza
Receive a Call
#include <SoftwareSerial.h>	
!
SoftwareSerial phone(2, 3);	
!
unsigned long lastCallTime = 0;	
String buffer;	
!
void setup()	
{	
// start talking to phone over serial	
phone.begin(9600);	
	
// start talking to computer over serial	
// to receive trigger and send debug	
// messages	
Serial.begin(9600);	
}	
!
void loop()	
{	
// check for calls	
bool callReceived = checkForCalls();	
	
// if we got a call send a message to the computer	
if (callReceived)	
{	
Serial.println("I got a call :)");	
}	
}
bool checkForCalls()	
{	
bool callReceived = false;	
if (phone.available())	
{	
char newChar = (char)phone.read();	
	
if (isNewLine(newChar))	
{	
if (!buffer.equals("") && !buffer.equals(" "))	
{	
Serial.println(buffer);	
if (buffer.indexOf("RING") != -1)	
{	
lastCallTime = millis();	
callReceived = true;	
}	
}	
buffer = "";	
}	
else 	
{	
buffer = buffer + newChar;	
}	
}	
return callReceived;	
}	
!
bool isNewLine(char c)	
{	
return c == 'n' || c == 'r' || c == 't';	
}
@neilmendoza
DEMO
@neilmendoza
Android
@neilmendoza
https://github.com/mik3y/usb-serial-for-android
USB On The Go (OTG) Cable
@neilmendoza
http://www.amarino-toolkit.net/
Bluetooth
@neilmendoza
Mobile Music
+
@neilmendoza
DEMO
@neilmendoza
githhub.com/neilmendoza/musicalmachines
!
www.neilmendoza.com
!
@neilmendoza

More Related Content

What's hot

[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218
CAVEDU Education
 
Wemakeit - base workshop - openlabs
Wemakeit - base workshop - openlabsWemakeit - base workshop - openlabs
Wemakeit - base workshop - openlabs
Luca Pescatore
 
8051 microcontroller training (2) (sahil gupta 9068557926)
8051 microcontroller training  (2) (sahil gupta   9068557926)8051 microcontroller training  (2) (sahil gupta   9068557926)
8051 microcontroller training (2) (sahil gupta 9068557926)
Sahil Gupta
 
Mims effect
Mims effectMims effect
Mims effect
arnaullb
 
Soc
SocSoc
Arduino 101
Arduino 101Arduino 101
Arduino 101
josnihmurni2907
 
Led program
Led programLed program
Led program
Atul Uttam
 
Itsp documentation quadcopter flight controller based on kalman filters
Itsp documentation   quadcopter flight controller based on kalman filtersItsp documentation   quadcopter flight controller based on kalman filters
Itsp documentation quadcopter flight controller based on kalman filters
Jyotirmaya Mahanta
 
Plc operation part 3
Plc operation part 3Plc operation part 3
Plc operation part 3
Sakshi Vashist
 
Arduino Robotics workshop Day1
Arduino Robotics workshop Day1Arduino Robotics workshop Day1
Arduino Robotics workshop Day1
Sudar Muthu
 
Class8
Class8Class8
37471656 interrupts
37471656 interrupts37471656 interrupts
37471656 interrupts
tt_aljobory
 
Arduino IDE
Arduino IDEArduino IDE
Arduino IDE
creatjet3d labs
 
Schrödinger's ARM Assembly
Schrödinger's ARM AssemblySchrödinger's ARM Assembly
Schrödinger's ARM Assembly
Saumil Shah
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
Amarjeetsingh Thakur
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
Amarjeetsingh Thakur
 
Arduino
ArduinoArduino
Arduino
candrakur
 
Introduction to Arduino and Circuits
Introduction to Arduino and CircuitsIntroduction to Arduino and Circuits
Introduction to Arduino and Circuits
Jason Griffey
 
Arduino arduino boardnano
Arduino   arduino boardnanoArduino   arduino boardnano
Arduino arduino boardnano
clickengenharia
 
8051 interrupts
8051 interrupts8051 interrupts
8051 interrupts
Shreyans Pathak
 

What's hot (20)

[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218
 
Wemakeit - base workshop - openlabs
Wemakeit - base workshop - openlabsWemakeit - base workshop - openlabs
Wemakeit - base workshop - openlabs
 
8051 microcontroller training (2) (sahil gupta 9068557926)
8051 microcontroller training  (2) (sahil gupta   9068557926)8051 microcontroller training  (2) (sahil gupta   9068557926)
8051 microcontroller training (2) (sahil gupta 9068557926)
 
Mims effect
Mims effectMims effect
Mims effect
 
Soc
SocSoc
Soc
 
Arduino 101
Arduino 101Arduino 101
Arduino 101
 
Led program
Led programLed program
Led program
 
Itsp documentation quadcopter flight controller based on kalman filters
Itsp documentation   quadcopter flight controller based on kalman filtersItsp documentation   quadcopter flight controller based on kalman filters
Itsp documentation quadcopter flight controller based on kalman filters
 
Plc operation part 3
Plc operation part 3Plc operation part 3
Plc operation part 3
 
Arduino Robotics workshop Day1
Arduino Robotics workshop Day1Arduino Robotics workshop Day1
Arduino Robotics workshop Day1
 
Class8
Class8Class8
Class8
 
37471656 interrupts
37471656 interrupts37471656 interrupts
37471656 interrupts
 
Arduino IDE
Arduino IDEArduino IDE
Arduino IDE
 
Schrödinger's ARM Assembly
Schrödinger's ARM AssemblySchrödinger's ARM Assembly
Schrödinger's ARM Assembly
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Arduino
ArduinoArduino
Arduino
 
Introduction to Arduino and Circuits
Introduction to Arduino and CircuitsIntroduction to Arduino and Circuits
Introduction to Arduino and Circuits
 
Arduino arduino boardnano
Arduino   arduino boardnanoArduino   arduino boardnano
Arduino arduino boardnano
 
8051 interrupts
8051 interrupts8051 interrupts
8051 interrupts
 

Similar to Musical Machines and Flapping Phones

Arduino and Robotics
Arduino and RoboticsArduino and Robotics
Arduino and Robotics
Mebin P M
 
Scottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RADScottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RAD
lostcaggy
 
GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf
 GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf
GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf
alltiusind
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
Mujahid Hussain
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
SIGMATAX1
 
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
ShashiKiran664181
 
Android Things Linux Day 2017
Android Things Linux Day 2017 Android Things Linux Day 2017
Android Things Linux Day 2017
Stefano Sanna
 
PROGRAMMING ADC and DAC-mbed.pdf
PROGRAMMING ADC and DAC-mbed.pdfPROGRAMMING ADC and DAC-mbed.pdf
PROGRAMMING ADC and DAC-mbed.pdf
vidhyalakshmi153619
 
Edge_AI_Assignment_3.pdf
Edge_AI_Assignment_3.pdfEdge_AI_Assignment_3.pdf
Edge_AI_Assignment_3.pdf
ShivamMishra603376
 
Arduino Programming
Arduino ProgrammingArduino Programming
Arduino Programming
Dr Karthikeyan Periasamy
 
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
SANTIAGO PABLO ALBERTO
 
Fabric robots
Fabric robotsFabric robots
Fabric robots
Endian Neo
 
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
Jayanthi Kannan MK
 
arduino.ppt
arduino.pptarduino.ppt
arduino.ppt
sunilkumar652338
 
robotics presentation for a club you run
robotics presentation for a club you runrobotics presentation for a club you run
robotics presentation for a club you run
SunilAcharya37
 
Arduino intro.pptx
Arduino intro.pptxArduino intro.pptx
Arduino intro.pptx
SanthanaMari11
 
Powerful Electronics with Arduino
Powerful Electronics with ArduinoPowerful Electronics with Arduino
Powerful Electronics with Arduino
Abdallah Hodieb
 
Twin wheeler modified for arduino simplified serial protocol to sabertooth v21
Twin wheeler modified for arduino simplified serial protocol to sabertooth v21Twin wheeler modified for arduino simplified serial protocol to sabertooth v21
Twin wheeler modified for arduino simplified serial protocol to sabertooth v21
josnihmurni2907
 
How to use an Arduino
How to use an ArduinoHow to use an Arduino
How to use an Arduino
AntonAndreev13
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
Luki B. Subekti
 

Similar to Musical Machines and Flapping Phones (20)

Arduino and Robotics
Arduino and RoboticsArduino and Robotics
Arduino and Robotics
 
Scottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RADScottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RAD
 
GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf
 GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf
GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
 
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
 
Android Things Linux Day 2017
Android Things Linux Day 2017 Android Things Linux Day 2017
Android Things Linux Day 2017
 
PROGRAMMING ADC and DAC-mbed.pdf
PROGRAMMING ADC and DAC-mbed.pdfPROGRAMMING ADC and DAC-mbed.pdf
PROGRAMMING ADC and DAC-mbed.pdf
 
Edge_AI_Assignment_3.pdf
Edge_AI_Assignment_3.pdfEdge_AI_Assignment_3.pdf
Edge_AI_Assignment_3.pdf
 
Arduino Programming
Arduino ProgrammingArduino Programming
Arduino Programming
 
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
 
Fabric robots
Fabric robotsFabric robots
Fabric robots
 
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
 
arduino.ppt
arduino.pptarduino.ppt
arduino.ppt
 
robotics presentation for a club you run
robotics presentation for a club you runrobotics presentation for a club you run
robotics presentation for a club you run
 
Arduino intro.pptx
Arduino intro.pptxArduino intro.pptx
Arduino intro.pptx
 
Powerful Electronics with Arduino
Powerful Electronics with ArduinoPowerful Electronics with Arduino
Powerful Electronics with Arduino
 
Twin wheeler modified for arduino simplified serial protocol to sabertooth v21
Twin wheeler modified for arduino simplified serial protocol to sabertooth v21Twin wheeler modified for arduino simplified serial protocol to sabertooth v21
Twin wheeler modified for arduino simplified serial protocol to sabertooth v21
 
How to use an Arduino
How to use an ArduinoHow to use an Arduino
How to use an Arduino
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 

Recently uploaded

Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalRBuilding a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR
Peter Gallagher
 
"IOS 18 CONTROL CENTRE REVAMP STREAMLINED IPHONE SHUTDOWN MADE EASIER"
"IOS 18 CONTROL CENTRE REVAMP STREAMLINED IPHONE SHUTDOWN MADE EASIER""IOS 18 CONTROL CENTRE REVAMP STREAMLINED IPHONE SHUTDOWN MADE EASIER"
"IOS 18 CONTROL CENTRE REVAMP STREAMLINED IPHONE SHUTDOWN MADE EASIER"
Emmanuel Onwumere
 
一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
bttak
 
一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理
一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理
一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理
bttak
 
欧洲杯投注-欧洲杯投注押注app-欧洲杯投注押注app官网|【​网址​🎉ac10.net🎉​】
欧洲杯投注-欧洲杯投注押注app-欧洲杯投注押注app官网|【​网址​🎉ac10.net🎉​】欧洲杯投注-欧洲杯投注押注app-欧洲杯投注押注app官网|【​网址​🎉ac10.net🎉​】
欧洲杯投注-欧洲杯投注押注app-欧洲杯投注押注app官网|【​网址​🎉ac10.net🎉​】
akrooshsaleem36
 
买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样
买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样
买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样
nvoyobt
 
按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理
按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理
按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理
uwoso
 
欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】
欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】
欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】
hanniaarias53
 
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
bttak
 
欧洲杯体彩-欧洲杯体彩比赛投注-欧洲杯体彩比赛投注官网|【​网址​🎉ac99.net🎉​】
欧洲杯体彩-欧洲杯体彩比赛投注-欧洲杯体彩比赛投注官网|【​网址​🎉ac99.net🎉​】欧洲杯体彩-欧洲杯体彩比赛投注-欧洲杯体彩比赛投注官网|【​网址​🎉ac99.net🎉​】
欧洲杯体彩-欧洲杯体彩比赛投注-欧洲杯体彩比赛投注官网|【​网址​🎉ac99.net🎉​】
lopezkatherina914
 

Recently uploaded (10)

Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalRBuilding a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR
 
"IOS 18 CONTROL CENTRE REVAMP STREAMLINED IPHONE SHUTDOWN MADE EASIER"
"IOS 18 CONTROL CENTRE REVAMP STREAMLINED IPHONE SHUTDOWN MADE EASIER""IOS 18 CONTROL CENTRE REVAMP STREAMLINED IPHONE SHUTDOWN MADE EASIER"
"IOS 18 CONTROL CENTRE REVAMP STREAMLINED IPHONE SHUTDOWN MADE EASIER"
 
一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
 
一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理
一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理
一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理
 
欧洲杯投注-欧洲杯投注押注app-欧洲杯投注押注app官网|【​网址​🎉ac10.net🎉​】
欧洲杯投注-欧洲杯投注押注app-欧洲杯投注押注app官网|【​网址​🎉ac10.net🎉​】欧洲杯投注-欧洲杯投注押注app-欧洲杯投注押注app官网|【​网址​🎉ac10.net🎉​】
欧洲杯投注-欧洲杯投注押注app-欧洲杯投注押注app官网|【​网址​🎉ac10.net🎉​】
 
买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样
买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样
买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样
 
按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理
按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理
按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理
 
欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】
欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】
欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】
 
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
 
欧洲杯体彩-欧洲杯体彩比赛投注-欧洲杯体彩比赛投注官网|【​网址​🎉ac99.net🎉​】
欧洲杯体彩-欧洲杯体彩比赛投注-欧洲杯体彩比赛投注官网|【​网址​🎉ac99.net🎉​】欧洲杯体彩-欧洲杯体彩比赛投注-欧洲杯体彩比赛投注官网|【​网址​🎉ac99.net🎉​】
欧洲杯体彩-欧洲杯体彩比赛投注-欧洲杯体彩比赛投注官网|【​网址​🎉ac99.net🎉​】
 

Musical Machines and Flapping Phones

  • 1. @neilmendoza Musical Machines and Flapping Phones ! Neil Mendoza
  • 17. @neilmendoza #include <Stepper.h> ! // change this to fit the number of steps per revolution // for your motor const int stepsPerRevolution = 48; ! // initialize the stepper library on the motor shield Stepper myStepper(stepsPerRevolution, 12,13); ! // give the motor control pins names: const int pwmA = 3; const int pwmB = 11; const int brakeA = 9; const int brakeB = 8; const int dirA = 12; const int dirB = 13; ! void setup() { // set the PWM and brake pins so that the direction pins // can be used to control the motor: pinMode(pwmA, OUTPUT); pinMode(pwmB, OUTPUT); pinMode(brakeA, OUTPUT); pinMode(brakeB, OUTPUT); digitalWrite(pwmA, HIGH); digitalWrite(pwmB, HIGH); digitalWrite(brakeA, LOW); digitalWrite(brakeB, LOW); ! // set the motor speed (for multiple steps only): myStepper.setSpeed(2); } ! void loop() { myStepper.step(48); myStepper.step(-48); ! delay(2000); } Motor Shield R3 Code
  • 18. @neilmendoza Step Direction Driver Code int dirpin = 2; int steppin = 3; ! void setup() { pinMode(dirpin, OUTPUT); pinMode(steppin, OUTPUT); } ! void loop() { int i; ! digitalWrite(dirpin, LOW); // Set the direction. delay(100); ! ! for (i = 0; i<4000; i++) // Iterate for 4000 microsteps. { digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step. delayMicroseconds(500); // This delay time is close to top speed for this } // particular motor. Any faster the motor stalls. ! digitalWrite(dirpin, HIGH); // Change direction. delay(100); ! ! for (i = 0; i<4000; i++) // Iterate for 4000 microsteps { digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step. delayMicroseconds(500); // This delay time is close to top speed for this } // particular motor. Any faster the motor stalls. }
  • 21. @neilmendoza Simple MIDI Code #include <SoftwareSerial.h> ! int midiByte0 = -1; int midiByte1 = -1; int midiByte2 = -1; ! #define HI_NIBBLE(b) (((b)>>4) & 0x0F) #define LO_NIBBLE(b) ((b) & 0x0F) ! #define NOTE_ON_STATUS B1001 #define NOTE_OFF_STATUS B1000 #define CC_STATUS B1011 #define PITCHBEND_STATUS B1110 ! #define MIDI_BAUD_RATE 31250 ! const int LED = 13; const int MIDI_IN = 8; ! SoftwareSerial midiIn(MIDI_IN, 9); // RX, TX ! void setup() { pinMode(LED, OUTPUT); midiIn.begin(MIDI_BAUD_RATE); } ! void loop() { updateMidi(); } ! void noteOn(int channel, int note, int vel) { digitalWrite(LED, HIGH); } ! void noteOff(int channel, int note) { digitalWrite(LED, LOW); } void updateMidi() { int b = midiIn.read(); if(b!= -1) { midiByte2 = midiByte1; midiByte1 = midiByte0; midiByte0 = b; // only work if we've got a status byte // of some sort if(!(midiByte2 & B10000000)) return; int st = HI_NIBBLE(midiByte2); int channel = LO_NIBBLE(midiByte2); // now check to see if we have a midi if(st == NOTE_ON_STATUS) { if(midiByte0 == 0) { // if the volume is zero, it's a note off noteOff(channel, midiByte1); } else { noteOn(channel, midiByte1, midiByte0); } } else if(st == NOTE_OFF_STATUS) { noteOff(channel, midiByte1); } } }
  • 22. @neilmendoza MIDI to Frequency Code #include <SoftwareSerial.h> ! int midiByte0 = -1; int midiByte1 = -1; int midiByte2 = -1; ! #define HI_NIBBLE(b) (((b)>>4) & 0x0F) #define LO_NIBBLE(b) ((b) & 0x0F) ! #define NOTE_ON_STATUS B1001 #define NOTE_OFF_STATUS B1000 #define CC_STATUS B1011 #define PITCHBEND_STATUS B1110 ! #define MIDI_BAUD_RATE 31250 ! const unsigned LED_PIN = 13; const unsigned STEP_PIN = 3; const unsigned DIR_PIN = 2; const unsigned MIDI_IN_PIN = 10; ! SoftwareSerial midiIn(MIDI_IN_PIN, 9); // RX, TX ! unsigned long halfPeriodMicros = 0; ! void setup() { pinMode(LED_PIN, OUTPUT); pinMode(STEP_PIN, OUTPUT); pinMode(DIR_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); digitalWrite(STEP_PIN, LOW); digitalWrite(DIR_PIN, LOW); midiIn.begin(MIDI_BAUD_RATE); } ! void loop() { if (halfPeriodMicros != 0) { digitalWrite(STEP_PIN, HIGH); delayMicroseconds(halfPeriodMicros); digitalWrite(STEP_PIN, LOW); delayMicroseconds(halfPeriodMicros); } } ! double midiToFrequency(int midiNote) { return 440.0 * exp(0.057762265 * (midiNote - 69.0)); } ! void noteOn(int channel, int midiNote, int vel) { halfPeriodMicros = 0.5 * 1000000.0 / midiToFrequency(midiNote); digitalWrite(LED_PIN, HIGH); } ! void noteOff(int channel, int midiNote) { halfPeriodMicros = 0; digitalWrite(LED_PIN, LOW); } ! void updateMidi() { int b = midiIn.read(); if(b != -1) { midiByte2 = midiByte1; midiByte1 = midiByte0; midiByte0 = b; // only work if we've got a status byte // of some sort if(!(midiByte2 & B10000000)) return; int st = HI_NIBBLE(midiByte2); int channel = LO_NIBBLE(midiByte2); // now check to see if we have a midi if(st == NOTE_ON_STATUS) { if(midiByte0 == 0) { // if the volume is zero, it's a note off noteOff(channel, midiByte1); } else { noteOn(channel, midiByte1, midiByte0); } } else if(st == NOTE_OFF_STATUS) { noteOff(channel, midiByte1); } } }
  • 23. @neilmendoza Oscillator Code #include "Oscillator.h" unsigned long Oscillator::elapsedMicros = 0; ! Oscillator::Oscillator(unsigned channel) : channel(channel), periodMicros(0), halfPeriodMicros(0) {} void Oscillator::noteOn(unsigned channel, unsigned note, unsigned vel) { if (this->channel == channel) { periodMicros = 1000000.0 / midiToFrequency(note); halfPeriodMicros = 0.5 * periodMicros; } }; ! void Oscillator::noteOff(unsigned channel, unsigned note) { if (this->channel == channel) { periodMicros = 0; halfPeriodMicros = 0; } }; ! void Oscillator::update() { if(periodMicros > 0) { unsigned long elapsedPeriodMicros = elapsedMicros % periodMicros; if(elapsedPeriodMicros > halfPeriodMicros != !wave) { // wave form has flipped wave = !wave; if (wave) risingEdge(); else fallingEdge(); } } }; ! double Oscillator::midiToFrequency(int midiNote) { return 440.0 * exp(0.057762265 * (midiNote - 69.0)); }
  • 25. @neilmendoza Percussion: Car Door Lock “Solenoid”
  • 27. @neilmendoza Car Door Lock Code = Blink int carDoorPin = 10; ! // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. pinMode(carDoorPin, OUTPUT); } ! // the loop routine runs over and over again forever: void loop() { digitalWrite(carDoorPin, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(carDoorPin, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }
  • 38. @neilmendoza Many phones still speak the same language as 1990s modems (AT commands) ATD0123456789 = Call 0123456789 AT+CHUP = Hang up call
  • 39. @neilmendoza Cheap phones that talk serial Sony Ericsson T237(US)/T230(UK)
  • 42. @neilmendoza Make a Call #include <SoftwareSerial.h> ! const String PHONE_NUMBER = “07956641707"; ! SoftwareSerial phone(2, 3); ! void setup() { // start talking to phone over serial phone.begin(9600); // start talking to computer over serial // to receive trigger and send debug // messages Serial.begin(9600); } ! void loop() { } ! void serialEvent() { // received a serial event call number if (Serial.available()) { // prepare the AT command String command("ATD"); command += PHONE_NUMBER; command += ";"; // send it to the phone phone.println(command); // debug message Serial.print("Sent AT command: "); Serial.println(command); // clear the serial buffer and wait for // next time Serial.flush(); } }
  • 43. @neilmendoza Receive a Call #include <SoftwareSerial.h> ! SoftwareSerial phone(2, 3); ! unsigned long lastCallTime = 0; String buffer; ! void setup() { // start talking to phone over serial phone.begin(9600); // start talking to computer over serial // to receive trigger and send debug // messages Serial.begin(9600); } ! void loop() { // check for calls bool callReceived = checkForCalls(); // if we got a call send a message to the computer if (callReceived) { Serial.println("I got a call :)"); } } bool checkForCalls() { bool callReceived = false; if (phone.available()) { char newChar = (char)phone.read(); if (isNewLine(newChar)) { if (!buffer.equals("") && !buffer.equals(" ")) { Serial.println(buffer); if (buffer.indexOf("RING") != -1) { lastCallTime = millis(); callReceived = true; } } buffer = ""; } else { buffer = buffer + newChar; } } return callReceived; } ! bool isNewLine(char c) { return c == 'n' || c == 'r' || c == 't'; }