I am another annoying newbie.
I've had a go at writing code to measure input pulses , convert each pulse to a yards traveled measurement and display the distance on an LCD via I2C bus.
A big first up project and I seemed to have lost my way. Error seems to be in displaying the value. Do I need Serial.print command or can I just use Write.send? I don't understand the difference.
#include <Wire.h>
// Arduino analog input 5 - I2C SCL
// Arduino analog input 4 - I2C SDA
byte twi_addr = 0x80 >> 1; // I2C device address of lcd
int pinWheelpulseIn = 2; // D2 for wheel pulse Input - Measuring the Pulses
byte WheelpulseIn = 0; // declare this as a byte if the count is always less than 500
// so you don't have to disable interrupts when using in loop
byte dist = 0;
long intWheelpulseIn_Millis = 0;
// set up I2c and init LCD
void setup() {
Wire.begin ();
lcd2s_init ();
// Configure pin modesvoid loop()
WheelpulseIn= 0;
delay(500); //wait 1/2 second
byte pulseCount = WheelpulseIn; // get a snapshot of the count
float dist = pulseCount * 5.5; //multipler to convert to yards
Wire.begin(); // start Wire library as I2C-Bus Master
}
void lcd2s_init() {
Wire.beginTransmission (twi_addr); // transmit to device 0x80
Wire.send (0x8C); // send lcd clear command
Wire.endTransmission (); // stop transmitting
delay(3000);
}
void loop(){
Wire.beginTransmission(twi_addr); // transmit to device #44 (0x2c)
// device address is specified in datasheet
Wire.send(0x8c); // sends clear instruction
Wire.send("\Distance is\dist"); // sends dist value byte
Wire.endTransmission(); // stop transmitting
delay (5000);
dist++; // increment value
delay(1000);
}
void count(){
WheelpulseIn++;
pinMode(pinWheelpulseIn, INPUT);
attachInterrupt(0, count, HIGH); // call count when pin 2 goes high
}