|
Intro to Physical Computing Syllabus Research & Learning Other Class pages
ITP Help Pages |
Scott F2011-WED-630
Contact:
Class List:
Additional links of interestSuppliesSee http://itp.nyu.edu/physcomp/Intro/Supplies Notes from Class
simple switch code from class void setup() { // initialize the pin as an output. pinMode(2, OUTPUT); // initialize the pin as an input. pinMode(3,INPUT); } void loop() { if(digitalRead(3)==HIGH){ //if the switch is pressed
digitalWrite(2, HIGH); // set the LED on
}else{ //if it is not pressed
digitalWrite(2, LOW); // set the LED off
}
}
Purveyors of fine electronic goods :
Tom's taxonomy of Pcomp projects
mentioned in class
// constants to hold the output pin numbers:
const int redPin = 9;
const int greenPin = 10;
const int yellowPin = 11;
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);
}
}
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', 'y', or '0' throigh '9'.
// you don't care about any other value:
if (inByte == 'r') {
currentPin = redPin;
}
if (inByte == 'g') {
currentPin = greenPin;
}
if (inByte == 'y') {
currentPin = yellowPin;
}
if (inByte >= '0' && inByte <= '9') {
// map the incoming byte value to the range of the analogRead() command:
brightness = map(inByte, '0', '9', 0, 255);
// set the current pin to the current brightness:
analogWrite(currentPin, brightness);
}
}
}
|