digitalWrite(pin,value) // sets ‘pin’ to value (LOW or HIGH)
Example: blinking LED
int led = 13;
void setup() {
pinMode(led, OUTPUT); // digital pin as an output
}
void loop() {
digitalWrite(led, HIGH); // turn the LED on
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
analogWrite(pin,value); // writes ‘value’ to analog ‘pin’ // value = between 0 (off) and 255 (on)
const int sensorPin = A0; // select the input pin for the potentiometer
const int REDPin = 11; // select the pin for the LED
const int BLUEPin = 10;
const int GREENPin = 9;
int sensorValue = 0;
int outputValue = 0;
void setup() {
pinMode(REDPin, OUTPUT);
pinMode(BLUEPin, OUTPUT);
pinMode(GREENPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(REDPin,outputValue);
outputValue = map(sensorValue, 1023, 0, 0, 255);
analogWrite(BLUEPin,outputValue);
outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(GREENPin,outputValue);
Serial.println(sensorValue); // print out the value you read:
delay(1); // delay in between reads for stability
}