728x90
반응형
const int analogPin = A0;
void setup(){
Serial.begin(115200);
}
void loop(){
int analogValue = analogRead(analogPin);
Serial.println(analogValue);
}
// ANALOG IN(A0) -> POWER(5V) : 1023
// ANALOG IN(A0) -> POWER(3.3V) : 670 (1024/5V) * 3.3V = 675.8V
// ANALOG IN(A0) -> POWER(GND) : 0
const int analogPin = A0;
void setup(){
Serial.begin(115200);
}
void loop(){
int analogValue = analogRead(analogPin);
Serial.println(analogValue);
}
// ANALOG IN(A0) -> POWER(5V) : 1023
// ANALOG IN(A0) -> POWER(3.3V) : 670 (1024/5V) * 3.3V = 675.8V
// ANALOG IN(A0) -> POWER(GND) : 0
// Potentiometer 0 ~ 1023 Lotate and check
const int ledPin = 10;
const int analogPin = A0;
void setup(){
}
void loop(){
int sensorInput = analogRead(analogPin);
analogWrite(ledPin, sensorInput/4);
}
// Depends on Potentiometer input adjust LED bright.
const int led[6] = {3, 4, 6, 9, 10, 11};
const int analogPin = A0;
void setup(){
int i;
for (i = 0; i <= 5; i++)
{
pinMode(led[i], OUTPUT);
}
}
void loop(){
int sensorInput = analogRead(analogPin);
for (int n = 0; n<=5; n++){
if(sensorInput > 1024/7*(1+n))
digitalWrite(led[n], HIGH);
else digitalWrite(led[n], LOW);
}
}
/// Digital Bar mesurement
const int trig_pin = 11;
const int echo_pin = 12;
void setup(){
pinMode(trig_pin, OUTPUT);
pinMode(echo_pin, INPUT);
Serial.begin(115200);
}
void loop(){
digitalWrite(trig_pin, LOW);
delayMicroseconds(2);
digitalWrite(trig_pin, HIGH);
delayMicroseconds(10);
digitalWrite(trig_pin, LOW);
long duration = pulseIn(echo_pin, HIGH);
long distance = (duration/2) / 29.1;
Serial.print(distance);
Serial.println(" cm");
}
// pulseln
728x90
반응형
'Firmware & Embedded > AVR' 카테고리의 다른 글
attachInterrupt (0) | 2022.09.22 |
---|---|
PWM - Timer Library (0) | 2022.09.22 |
Basic Arduino (serial.read) (0) | 2022.09.21 |
Basic Arduino (by circuit) (0) | 2022.09.21 |
Check the built-in LED using Arduino IDE (0) | 2022.09.20 |