c_cpp 使用Arduino的现代能量计
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 使用Arduino的现代能量计相关的知识,希望对你有一定的参考价值。
int unit = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A1);
delay(80);
int pulse = 0;
if(sensorValue > 200)pulse = 1;
else pulse = 0;
if(pulse)unit = unit +1;
Serial.println("Total Pulse : "+ String(unit) +" Unit: " + String(unit/16));
delay(500);
}
/* MEM -- Modern Energy Meter
The circuit:
LCD RS pin to digital pin 12
LCD Enable pin to digital pin 11
LCD D4 pin to digital pin 5
LCD D5 pin to digital pin 4
LCD D6 pin to digital pin 3
LCD D7 pin to digital pin 2
LCD R/W pin to ground
10K resistor:
ends to +5V and ground
wiper to LCD VO pin (pin 3)
*/
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int unit = 0;
void setup() {
lcd.begin(16, 2);
lcd.print("Welcome to MEM");
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A1);
delay(80);
int pulse = 0;
if (sensorValue > 200)pulse = 1;
else pulse = 0;
if (pulse)unit = unit + 1;
Serial.println("Total Pulse : " + String(unit) + " Unit: " + String(unit / 16));
// Display Data in LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Pulse:" + String(unit));
lcd.setCursor(16, 1);
lcd.print("Unit:" + String(unit / 16));
delay(500);
}
以上是关于c_cpp 使用Arduino的现代能量计的主要内容,如果未能解决你的问题,请参考以下文章
Arduino配合电位计和oled液晶屏显示波形 Processing联动
Arduino配合电位计和oled液晶屏显示波形 Processing联动
Arduino配合电位计和oled液晶屏显示波形 Processing联动
Arduino配合电位计和oled液晶屏显示波形 Processing联动
c_cpp 使用arduino数字引脚与外界联系。
c_cpp 改进的firmata协议,适用于使用ttyATH0串口接口与arduino端通信的arduino YUN linux端。