Tuesday, November 28, 2017

Final Project with Everything Together

Here I have attached the Ping Sensor, LED lights, the piezo buzzer, and the Aruduino.

Here is the code that I used for the Arduino
#define echoPin 10 // Echo Pin
#define trigPin 9 // Trigger Pin



const int freq = 5500;
const int dur = 20;
const int buzzer = 8;
const int red1 = 11;
const int yellow1 = 13;
const int green1 = 12;



int maximumRange = 200; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance



void setup() {
  // put your setup code here, to run once:{
 pinMode(buzzer, OUTPUT);
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
 pinMode(green1, OUTPUT);
 pinMode(yellow1, OUTPUT);
 pinMode(red1, OUTPUT);

 digitalWrite(green1, HIGH);
 digitalWrite(yellow1, HIGH);
 digitalWrite(red1, HIGH);


 delay(300);
 digitalWrite(green1, LOW);
 digitalWrite(yellow1, LOW);
 digitalWrite(red1, LOW);

 tone(buzzer, 4000, 3000);

}



void loop() {
  // put your main code here, to run repeatedly: {
/* The following trigPin/echoPin cycle is used to determine the
 distance of the nearest object by bouncing soundwaves off of it. */
 digitalWrite(trigPin, LOW);
 delayMicroseconds(2);


 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10);

 digitalWrite(trigPin, LOW);
 duration = pulseIn(echoPin, HIGH);

 //Calculate the distance (in cm) based on the speed of sound.
 distance = duration/58.2;


 if (distance < 7){
   digitalWrite(green1, LOW);
   digitalWrite(yellow1, LOW);
   digitalWrite(red1, HIGH);


 } else if (distance < 15){
   digitalWrite(green1, HIGH);
   digitalWrite(yellow1, LOW);
   digitalWrite(red1, LOW);


 } else if (distance < 20){
   digitalWrite(green1, LOW);
   digitalWrite(yellow1, HIGH);
   digitalWrite(red1, LOW);


 } else if (distance < 25){
   digitalWrite(green1, LOW);
   digitalWrite(yellow1, HIGH);
   digitalWrite(red1, LOW);


 } else if (distance < 30){
   digitalWrite(green1, LOW);
   digitalWrite(yellow1, HIGH);
   digitalWrite(red1, LOW);


 }

 if(distance < 7){
   tone(buzzer, 4000, 3000);
   delay(5);
 } else if (distance < 15){
   tone(buzzer, freq, dur);
   delay(10);
 } else if (distance < 20){
   tone(buzzer, freq, dur);
   delay(15);
 } else if (distance < 25){
   tone(buzzer, freq, dur);
   delay(20);
 } else if (distance < 30){
   tone(buzzer, freq, dur);
   delay(25);
 }



 //Delay 50ms before next reading.
 delay(50);
}

 Here's the Final Result of putting it together and adding in the code.


Learning how to use the buzzer















I learned to change the pitch and make it change between pitches.


Tuesday, November 7, 2017

Atari Punk Console

 10/31/2017
 10/31/2017
 10/31/2017
 10/31/2017
 11/02/2017
 11/02/2017
11/02/2017
11/02/2017
I broke D2 in half trying to it out. Had to Re-order it.