|
Intro to Physical Computing Syllabus Research & Learning Other Class pages
ITP Help Pages |
Scott F2011-THURS-1230
Contact:
Class List:
Additional links of interestClass ReschedulingAs a reminder, our class on Thursday the 6th needs to be moved to a different date. I scheduled some work in Chicago before I knew I would be teaching Thursdays. The dates I was thinking are Monday Oct 3 9:30-12 or Tuesday October 4 12:30-3. Thank you all for your understanding and general wonderfulness. Please let me know what you think, and I can arrange it with Gordie. Vote here : https://docs.google.com/document/d/1BqE5T5iF0X3tSuywa2yARMNa4PphdKTkAN4v9Di7Ro8/edit?hl=en_US SuppliesSee http://itp.nyu.edu/physcomp/Intro/Supplies Notes from Class
//example to blink at a variable rate
//led on pin 2, pot on A0
int potVal=0;
void setup(){
}
void loop(){
potVal=analogRead(A0);
digitalWrite(2, HIGH);
delay(potVal);
digitalWrite(2, LOW);
delay(potVal);
}
//Example for ranging our photocell
int potVal=0;
int mappedVal=0;
void setup(){
Serial.begin(9600);
}
void loop(){
potVal=analogRead(A0);
//photocell low was about 240, high was about 810
mappedVal=map(potVal, 240, 810, 0, 1023);
Serial.print("mapped Value : ");
Serial.print(mappedVal);
Serial.print("\t");
Serial.print("Photocell value : ");
Serial.println(potVal);
delay(10);
}
//Example mapping to see what values mean to voltages
//each increment = about .049V
int potVal=0;
int mappedVal=0;
void setup(){
Serial.begin(9600);
}
void loop(){
potVal=analogRead(A0);
mappedVal=map(potVal, 0, 1023, 0, 500);
Serial.print("Voltage : ");
Serial.print(mappedVal);
Serial.print("\t");
Serial.print("Arduino's value : ");
Serial.println(potVal);
delay(10);
}
Purveyors of fine electronic goods :
Tom's taxonomy of Pcomp projects
// constants to hold the output pin numbers:
const int bluePin = 11;
const int redPin = 9;
const int greenPin = 10;
int currentPin = 0; // current pin to be faded
int brightness = 0; // current brightness level
void setup() {
// initiate serial communication:
Serial.begin(9600);
// a for loop can simplify pin assignments
for(int x=9;x<12;x++){
pinMode(x, OUTPUT);
analogWrite(x, 255);
}
}
void loop() {
// if there's any serial data in the buffer, read a byte:
if (Serial.available() > 0) {
int inByte = Serial.read();
// respond to the values 'r', 'g', 'b', or '0' through '9'.
// you don't care about any other value:
if (inByte == 'r') {
currentPin = redPin;
}
if (inByte == 'g') {
currentPin = greenPin;
}
if (inByte == 'b') {
currentPin = bluePin;
}
if (inByte >= '0' && inByte <= '9') {
// map the incoming byte value to the range of the analogRead() command:
brightness = map(inByte, '0', '9', 255, 0);
// set the current pin to the current brightness:
analogWrite(currentPin, brightness);
}
}
}
|