selcuk1010
Üye
- Katılım
- 13 Ara 2017
- Mesajlar
- 27
- Puanları
- 1
Merhaba arkadaşlar bu arduino kodundaki pwm'in frekansı kaç HZ?
#include <LiquidCrystal.h>
#define buck 9
#define boost 6
#define output A0
#define POT A1
bool boostMode = 0;
bool buckMode = 0;
uint8_t PWM = 0;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup()
{
lcd.begin(16, 2);
pinMode( buck, OUTPUT );
pinMode( boost, OUTPUT );
pinMode( output, INPUT );
pinMode( POT, INPUT );
digitalWrite( buck, LOW );
digitalWrite( boost, LOW );
}
void loop()
{
float voltage = 0;
uint16_t adc = analogRead( output );
uint16_t potAC = analogRead( POT );
adc = map( adc, 0 , 1023, 0, 5 );
potAC = map( potAC, 0, 1023, 0, 255 );
voltage = adc / 0.2083;
lcd.setCursor(0, 0);
lcd.print(voltage);
if( potAC <= 125 )
{
boostMode = false;
buckMode = true;
}
if( potAC > 125 )
{
boostMode = true;
buckMode = false;
}
if( buckMode )
{
PWM = map( potAC, 0, 125, 35, 255 );
analogWrite( buck, PWM );
analogWrite( boost, 0 );
}
if( boostMode )
{
PWM = map( potAC, 125 , 255, 10, 47 );
analogWrite( buck, 255 );
analogWrite( boost, PWM );
}
}