Category: Assignment-10A

PushButtons (Circuit 07)

IMG_1999

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
  Button
 
 Turns on and off a light emitting diode(LED) connected to digital  
 pin 13, when pressing a pushbutton attached to pin 2. 
 
 
 The circuit:
 * LED attached from pin 13 to ground 
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground
 
 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.
 
 
 created 2005
 by DojoDave <http: //www.0j0.org>
 modified 30 Aug 2011
 by Tom Igoe
 
 This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/Button
 */
 
// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
 
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
 
void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}
 
void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
 
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}
</http:>

Screen Shot 2014-11-17 at 7.25.47 PM

Buttons

Buttons_bb

int ledPin = 9; // choose the pin for the LED 
int inputPin1 = 3; // button 1 
int inputPin2 = 2; // button 2 
 
void setup() { 
  pinMode(ledPin, OUTPUT); // declare LED as output 
  pinMode(inputPin1, INPUT); // make button 1 an input 
  pinMode(inputPin2, INPUT); // make button 2 an input 
} 
 
int value = 0; 
void loop(){ 
  if (digitalRead(inputPin1) == LOW) { value--; } 
  else if (digitalRead(inputPin2) == LOW) { value++; } 
  value = constrain(value, 0, 255); 
  analogWrite(ledPin, value); 
  delay(10); 
}

Assignment 10: Pushbuttons

Unfortunately, I took no video. Use your imagination.

IMG_1084

Buttons_bb

int ledPin = 13; // choose the pin for the LED 
int inputPin1 = 3; // button 1 
int inputPin2 = 2; // button 2 
 
void setup() { 
  pinMode(ledPin, OUTPUT); // declare LED as output 
  pinMode(inputPin1, INPUT); // make button 1 an input 
  pinMode(inputPin2, INPUT); // make button 2 an input 
} 
 
void loop(){ 
  if (digitalRead(inputPin1) == LOW) { 
    digitalWrite(ledPin, LOW); // turn LED OFF 
  } else if (digitalRead(inputPin2) == LOW) { 
    digitalWrite(ledPin, HIGH); // turn LED ON 
  } 
}

 

Circuit 07 clair

video of circuit 07
MOV_8733

picture of circuit 07
IMG_0221

fritzing diagram
circuit07

code
/*
Button

Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
 The circuit:
 * LED attached from pin 13 to ground 
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground
 
 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.
 
 
 created 2005
 by DojoDave <http://www.0j0.org>
 modified 30 Aug 2011
 by Tom Igoe
 
 This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/Button
 */
 
// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
 
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
 
void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}
 
void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
 
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}

Assignment-10A: PushButtons (Circuit 07)

Assignment-10A: PushButtons (Circuit 07)

excercise 7image
Diagram

Setting Up
Setting Up

In action:

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
  Button
 
 Turns on and off a light emitting diode(LED) connected to digital  
 pin 13, when pressing a pushbutton attached to pin 7. 
 
 
 The circuit:
 * LED attached from pin 13 to ground 
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground
 
 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.
 
 
 created 2005
 by DojoDave 
 modified 17 Jun 2009
 by Tom Igoe
 
  http://www.arduino.cc/en/Tutorial/Button
 */
 
// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
 
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
 
void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}
 
void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
 
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}

Push Button

 

 

http://youtu.be/4oNz_M8QiUoCIRC-07

C07Pic

 

 
// Will Taylor
// Circuit 07
 
/*
 
* Button
 
* by DojoDave &lt;http://www.0j0.org&gt;
 
*
 
* Turns on and off a light emitting diode(LED) connected to digital
 
* pin 13, when pressing a pushbutton attached to pin 7.
 
* http://www.arduino.cc/en/Tutorial/Button
 
*/
 
int ledPin = 13; // choose the pin for the LED
 
int inputPin = 2; // choose the input pin (for a pushbutton)
 
int val = 0; // variable for reading the pin status
 
void setup() {
 
pinMode(ledPin, OUTPUT); // declare LED as output
 
pinMode(inputPin, INPUT); // declare pushbutton as input
 
}
 
void loop(){
 
val = digitalRead(inputPin); // read input value
 
if (val == HIGH) { // check if the input is HIGH
 
digitalWrite(ledPin, LOW); // turn LED OFF
 
} else {
 
digitalWrite(ledPin, HIGH); // turn LED ON
 
}
 
}

Arduino 07

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
void setup() {
 pinMode(ledPin, OUTPUT); // declare LED as output
 pinMode(inputPin, INPUT); // declare pushbutton as input
}
void loop(){
 val = digitalRead(inputPin); // read input value
 if (val == HIGH) { // check if the input is HIGH
 digitalWrite(ledPin, LOW); // turn LED OFF
 } else {
 digitalWrite(ledPin, HIGH); // turn LED ON
 }
}

 

#7

Please ignore the random chatter in the background of the video but mostly ignore my incredibly creepy laugh

7

7

/*
  Button
 
 Turns on and off a light emitting diode(LED) connected to digital  
 pin 13, when pressing a pushbutton attached to pin 7. 
 
 
 The circuit:
 * LED attached from pin 13 to ground 
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground
 
 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.
 
 
 created 2005
 by DojoDave 
 modified 17 Jun 2009
 by Tom Igoe
 
  http://www.arduino.cc/en/Tutorial/Button
 */
 
// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
 
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
 
void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}
 
void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
 
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}

or

int ledPin = 13; // choose the pin for the LED 
int inputPin1 = 3; // button 1 
int inputPin2 = 2; // button 2 
 
void setup() { 
  pinMode(ledPin, OUTPUT); // declare LED as output 
  pinMode(inputPin1, INPUT); // make button 1 an input 
  pinMode(inputPin2, INPUT); // make button 2 an input 
} 
 
void loop(){ 
  if (digitalRead(inputPin1) == LOW) { 
    digitalWrite(ledPin, LOW); // turn LED OFF 
  } else if (digitalRead(inputPin2) == LOW) { 
    digitalWrite(ledPin, HIGH); // turn LED ON 
  } 
}

Proximity Sensor experiment

Rather than wiring up the given diagrams for sensors from the book, I made a circuit using something I hadn’t used before. I made a simple circuit which plays tones based on a value measured from a proximity sensor.

Here is the video:

Here is the fritzing diagram:

proximity_mbk

Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* 
 * Proximity instrument
 * This is totally not anything like a theramin.
 * Author: Matthew Kellogg
 * Date: October 22, 2014
 */
int ledPin = 5;    // LED connected to digital pin 9
 
void setup()  { 
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
} 
 
static const int thresh = 160;
 
void loop()  {
  int val = analogRead(0);
  if (val &gt; thresh){
    analogWrite(ledPin, map(val, 30, 950, 0, 255));
    tone(11, map(val, thresh, 950, 60, 4400));
  } else { 
    analogWrite(ledPin, 0);
    noTone(11);
  }
}

Assignment 10A

PushButton.

IRL:
20141028_181119

In Fritzing:
assignment 10A pushbutton fritzing

In Action:

My Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const int buttonPin1 = 2;     
const int buttonPin2 = 3;
const int ledPin =  9;      
 
int buttonState1 = 0;     
int buttonState2 = 0;
 
void setup() {
  pinMode(ledPin, OUTPUT);      
  pinMode(buttonPin1, INPUT);     
  pinMode(buttonPin2, INPUT);
}
 
void loop(){
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  int value = 0;
  if (buttonState1 == HIGH) {  
      Serial.println("1");    
      value += 100;
  } 
  if (buttonState2 == HIGH) {
      Serial.println("2");
      value += 100; 
  }
  analogWrite(ledPin, value);
  delay(15);
}