content:
Charge- positive and negative are carried by protons and electrons. Like charges repel each other and unlike charges attract each other. An object without a charge is neutral.
Volts- power of the protons and electrons moving trough a circut
Electrostatic Force- the attractive or repulsive force between two charged objects.
Coulomb's law- like charges repel and opposite charges attract, with a force proportional to the product of the charges and inversely proportional to the square of the distance between them.
Resistance- voltage applied to the electric current which flows through it
Electric Circuit- a path in which electrons from a voltage or current source flow
Voltage- the difference in electric potential between two points
Electric Current- The flow of electric charge
Magnetic Field- a vector field that describes the magnetic influence of electric charges in relative motion and magnetized materials
Amperes- unit of electric current to a flow.
Power- the amount of energy transferred or converted per unit time
int speakerPin = 3 ;
//PIN VARIABLES
//the motor will be controlled by the motor A pins on the motor driver
const int AIN1 = 13; //control pin 1 on the motor driver for the right motor
const int AIN2 = 12; //control pin 2 on the motor driver for the right motor
const int PWMA = 11; //speed control pin on the motor driver for the right motor
int switchPin = 7; //switch to turn the robot on and off
//VARIABLES
int motorSpeed = 2; //starting speed for the motor
void setup() {
pinMode(6, OUTPUT); // set pin to output
pinMode(5, OUTPUT); // set pin 8 to output
pinMode(4, OUTPUT);
pinMode(2, OUTPUT); // set pin to output
pinMode(1, OUTPUT); // set pin 8 to output
pinMode(0, OUTPUT); // set pin 8 to output
pinMode(speakerPin, OUTPUT);
pinMode(switchPin, INPUT_PULLUP); //set this as a pullup to sense whether the switch is flipped
Serial.begin(9600); //begin serial communication with the computer
Serial.println("Enter motor speed (0-255)... ");
}
void loop()
{
play('a', 1);
play('b', 1);
play('a', 1);
play('b', 1);
play('a', 1);
digitalWrite(6, HIGH);
delay(100);
digitalWrite(5, HIGH); // Turn on the LED
delay(100); // Wait for 0.1 seconds
digitalWrite(4, HIGH); // Turn on the LED
delay(100); // Wait for 0.1
digitalWrite(2, HIGH); // Turn on the LED
delay(100); // Wait for 0.1 seconds
digitalWrite(1, HIGH); // Turn on the LED
delay(100); // Wait for 0.1 seconds
digitalWrite(0, HIGH); // Turn on the LED
delay(100); // Wait for 0.1 seconds
digitalWrite(6, LOW);
delay(100);
digitalWrite(5, LOW);
delay(100);
digitalWrite(4, LOW);
digitalWrite(2, LOW);
delay(100);
digitalWrite(1, LOW);
delay(100);
digitalWrite(0, LOW);
delay(100);
digitalWrite(0, HIGH);
delay(100);
digitalWrite(1, HIGH);
delay(100);
digitalWrite(2, HIGH);
delay(100);
digitalWrite(4, HIGH);
delay(100);
digitalWrite(5, HIGH);
delay(100);
digitalWrite(6, HIGH);
delay(100);
digitalWrite(6, LOW);
delay(100);
digitalWrite(5, LOW);
delay(100);
digitalWrite(4, LOW);
delay(100);
digitalWrite(2, LOW);
delay(100);
digitalWrite(1, LOW);
delay(100);
digitalWrite(0, LOW);
delay(100);
}
void play( char note, int beats)
{
int numNotes = 14; // number of notes in our note and frequency array (there are 15 values, but arrays start at 0)
//Note: these notes are C major (there are no sharps or flats)
//this array is used to look up the notes
char notes[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'D', 'E', 'F', 'G', 'A', 'B', ' '};
//this array matches frequencies with each letter (e.g. the 4th note is 'f', the 4th frequency is 175)
int frequencies[] = {131, 147, 165, 175, 196, 220, 247, 262, 294, 330, 349, 392, 440, 494, 0};
int currentFrequency = 0; //the frequency that we find when we look up a frequency in the arrays
int beatLength = 150; //the length of one beat (changing this will speed up or slow down the tempo of the song)
//look up the frequency that corresponds to the note
for (int i = 0; i < numNotes; i++) // check each value in notes from 0 to 14
{
if (notes[i] == note) // does the letter passed to the play function match the letter in the array?
{
currentFrequency = frequencies[i]; // Yes! Set the current frequency to match that note
}
}
//play the frequency that matched our letter for the number of beats passed to the play function
tone(speakerPin, currentFrequency, beats * beatLength);
delay(beats * beatLength); //wait for the length of the tone so that it has time to play
delay(50); //a little delay between the notes makes the song sound more natural
}
/* CHART OF FREQUENCIES FOR NOTES IN C MAJOR
Note Frequency (Hz)
c 131
d 147
e 165
f 175
g 196
a 220
b 247
C 262
D 294
E 330
F 349
G 392
A 440
B 494
*/