Day 7

For lab we had to connect a speaker to the arduino, and modify the code to play a song.
Here's my code for that.

//Specify digital pin on the Arduino that the positive lead of the speaker is

int speakerPin = 9;
const int POT=0;
int val = 0;
void setup()
{
   Serial.begin(9600); //Start Serial Communication
}

//close setup
void loop() {
 /*Tone needs 2 arguments, but can take three
 1) Pin#
 2) Frequency - this is in hertz (cycles per second) which determines the
pitch of the noise made
 3) Duration - how long the tone plays
 */
  val = analogRead(POT);
  if (val<=139)
  {
 tone(speakerPin, 1000, 500);
 delay(1000);
}

if (val<=147 && val>=139)
  {
   tone(speakerPin, 150,500);
 delay(1000);
  }
 
if (val>=147&&val<=153)
{
 
 tone(speakerPin,400,500);
 delay(1000);
}

if (val>=154)
{
 
 tone(speakerPin,200,500);
 delay(1000);
}
Serial.println(val); //Print it to the serial port
 delay(500);
}

For homework we had to write a program that simulats rolling dice heres a screenshot of my code working

For this homework I could only get the dice program running I could not get the computing factorial program to run.



Comments

Popular posts from this blog

Day 5

Day 22 Nov 14

Day 21 Nov 9