Search

Physical Computing Week 2: Thursday


Quiz:


1. 0 - 1023. 1023 is 0011 1111 1111 in binary or 2^10

2.

3.

4. You can wire the sensor to power and test the voltage by using a multimeter and then calculate the value range from there using the analog to digital conversion ratio.


5. 1023/5V = 10/x

10 points = .0488 V


6. The voltage is .00488 V per point


7. 1023/3.3v = 10/x

10 points = .0322 V

1 point = .00322 V


8. This principle is called PMW or pulse width modulation which creates an average voltage by modulating the number of pulses over time. This pulse/time ratio is described as a duty cycle, which describes the proportion of "on" time and "off" time. A duty cycle of 100% is effectively always on, whereas a duty cycle of 0% is off. A duty cycle of 50% means that the "on" pulse time and "off" pulse time are equal, which will resemble a square wave on an oscilloscope.


9. The tone() command controls the frequency of the pulses, which is denoted in hertz and records the number of wave cycles per second.


10. analogWrite() has an output resolution of 0 - 255.


11.

const int LedPin = 9; //pin LED is attached to
int analogValue = 0; //value read from potentiometer
int brightness = 0; //PWM pin that LED is on

void setup() {
 // initialize serial communications at 9600 bps:
    Serial.begin(9600);
    // declare the led pin as an output:
    pinMode(LedPin, OUTPUT);
}


void loop() {
analogValue = analogRead(A0); //read potentiometer value
brightness = map(analogValue,0,1023,0,255);
analogWrite(LedPin, brightness); // PWM the LED with the brightness value
Serial.println(brightness); //  // print the brightness value back to the serial monitor
}