Professional Documents
Culture Documents
OUTPUT); }
void loop() { digitalWrite(13, HIGH); delayMicroseconds(100); // Approximately 10% duty cycle @ 1KHz digitalWrite(13, LOW); delayMicroseconds(1000-100); } 2) int ledPin = 9; // LED connected to digital pin 9
int analogPin = 3; // potentiometer connected to analog pin 3 int val = 0; void setup() { pinMode(ledPin, OUTPUT); // sets the pin as output } void loop() { val = analogRead(analogPin); // read the input pin analogWrite(ledPin, val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255 } 3)
int potPin = 2; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED int val = 0; void setup() { pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT } // variable to store the value coming from the sensor
void loop() { val = analogRead(potPin); // read the value from the sensor .
1023
digitalWrite(ledPin, HIGH); // turn the ledPin on delay(val); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off delay(val); } // stop the program for some time
#define I2C_ADDR 0x27 // <<----- Add your address here. Find it from I2C Scanner #define BACKLIGHT_PIN #define En_pin 2 #define Rw_pin 1 #define Rs_pin 0 #define D4_pin 4 #define D5_pin 5 #define D6_pin 6 #define D7_pin 7 3
int analogPin = 0;
LiquidCrystal_I2C
lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup() { lcd.begin (16,2); // <<----- My LCD was 16x2 pinMode(analogPin, INPUT);
void loop() { val= analogRead(analogPin); delay(1000); x=(val*5.0)/1024.0; y= val; // Backlight on/off every 3 seconds lcd.setCursor (0,1); // go to start of 2nd line lcd.print("voltaj= "); lcd.print(x); if(x<2) lcd.print(" hop") ; else lcd.print(" "); lcd.setCursor (1,0); lcd.print("bit= "); lcd.print(y); lcd.setBacklight(LOW); // Backlight off // go to start of 2nd line
lcd.setBacklight(HIGH);
// Backlight on