You are on page 1of 4

PWM 1) //HER HANG PN DE KULLANILABLR, disadvantage is that any interrupts will affect the timing, void setup() { pinMode(13,

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

// variable to store the read value

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

a number between 0 and

digitalWrite(ledPin, LOW); // turn the ledPin off delay(val); } // stop the program for some time

2C 1) #include <Wire.h> #include <LCD.h> #include <LiquidCrystal_I2C.h>

#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 n = 1; float x=0.0; int val = 0; int y=0;

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);

// Switch on the backlight lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); lcd.setBacklight(HIGH); lcd.home (); // go home

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

You might also like