플렉스 센서가 구부러짐에 따라 LED 스트립이 점차 밝아 지도록하고 싶습니다. 그러나 나는 플렉스 센서가 45 도일 때 LED 스트립이 점등되기를 원합니다. 그리고 나는 led strip이 45도 전에 떨어져 있기를 원합니다. Arduino에있는 제 코드는 다음과 같습니다.aurduino 굴곡 센서에서 45도에서 조명을 켜는 방법은 무엇입니까?
const int ledPin = 3; //pin 3 has PWM funtion
const int flexPin = A0; //pin A0 to read analog input
int degree; //save analog value
int sensor;
void setup(){
pinMode(ledPin, OUTPUT); //Set pin 3 as 'output'
Serial.begin(9600); //Begin serial communication
}
void loop(){
sensor = analogRead(flexPin); //Read and save analog value from potentiometer
if(degree<45){
(sensor = 0);
}
degree = map(sensor, 460, 850, 0, 90);
Serial.print("analog input: ");
Serial.print(sensor,DEC);
Serial.print(" degrees: ");
Serial.println(degree,DEC);
Serial.print(" ---------------------------------- ");
analogWrite(ledPin, degree); //Send PWM value to led
delay(50); //Small delay
}
그리고이는 잘 작동하지 않았다 :
const int ledPin = 3; //pin 3 has PWM funtion
const int flexPin = A0; //pin A0 to read analog input
int degree; //save analog value
int sensor;
void setup(){
pinMode(ledPin, OUTPUT); //Set pin 3 as 'output'
Serial.begin(9600); //Begin serial communication
}
void loop(){
sensor = analogRead(flexPin); //Read and save analog value from potentiometer
degree = map(sensor, 460, 850, 45, 90);
Serial.print("analog input: ");
Serial.print(sensor,DEC);
Serial.print(" degrees: ");
Serial.println(degree,DEC);
Serial.print(" ---------------------------------- ");
analogWrite(ledPin, degree); //Send PWM value to led
delay(50); //Small delay
}
하지만이 일을하지 않았다, 그래서 나는이 일을 시도했다. 그들은 0도에서 밝아지기 시작하고 90도에 가까워지면서 더 많이 얻습니다. 그러나 45도 이전에는 꺼져 있어야하고, 45도에서 밝아지고 90도에 가까워지면 더 많은 것을 얻을 수 있기를 바랍니다. 네가 나를 도울 수 있다면 정말 감사 할거야. 나는 너무나 지쳐서 노력하지 않고 어디로 가야할지 모르겠다.