You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hello 8) , i just wanna do a simple rangrefinder with a hc-sr04 and a tiny oled
128x64_i2c but no sucess ....
i try to combine 2 sketchs, 1 for the ultrasonic sensor and 1 for the screen.
So on the screen there is "hello world" and if i check the serial monitor on my
computeur i can see the range finder working well...
But i wanna have the value of the sensor on the screen and i cannot find my way
to it...
thanks and sorry for my english (french guy )
#include "U8glib.h"
int triggerPin = 7;
int echoPin = 8;
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(0, 20);
u8g.print("Hello World!");
}
void setup(void) {
Serial.begin(9600);
pinMode(triggerPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop(void) {
// picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
// rebuild the picture after some delay
delay(500);
int duration, distance; //Adding duration and distance
digitalWrite(triggerPin, HIGH); //triggering the wave(like blinking an LED)
delay(10);
digitalWrite(triggerPin, LOW);
duration = pulseIn(echoPin, HIGH); //a special function for listening and waiting for the wave
distance = (duration/2) / 29.1; //transforming the number to cm(if you want inches, you have to change the 29.1 with a suitable number
Serial.print(distance); //printing the numbers
Serial.print("cm"); //and the unit
Serial.println(" "); //just printing to a new line
}
Original issue reported on code.google.com by creazy...@gmail.com on 5 Feb 2015 at 6:22
The text was updated successfully, but these errors were encountered:
Original issue reported on code.google.com by
creazy...@gmail.com
on 5 Feb 2015 at 6:22The text was updated successfully, but these errors were encountered: