东芝光继电器评测#2 TLP3547项目中的应用
本帖最后由 北方 于 2018-10-11 16:33 编辑项目中的应用1、TLP3547的基本元件评测只是说明了其中的应用方案,具体在实践项目中,应用起来应该是更为方便。
2、这里先使用Blink程序,
用digital output来控制输入,这样可以点亮LED灯。
Arduino程序代码如下;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
视频如下
3. 然后使用距离传感器来启动LED等的点亮和关闭,
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
if (voltage <3) {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000);}
if (voltage > 3) {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}
}视频如下
页:
[1]