Sup guys,
I have a project where I want to measure the time an object needs to fall from a given height. That part is already done by adding a display to my Arduino UNO and giving out the measurments this way. But now I want to view my measurnents by sending them to my smartphone via the HC-05. This is what I already managed to do:
Arduino Sketch:
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
SoftwareSerial btSerial(rxPin, txPin);
String btData;
int adc_key_in = 0;
int zeit;
int Z=0;
void setup(){
pinMode(13, INPUT); digitalWrite(13, HIGH); // PullUp --> Eingang wird auf HIGH gesetzt
pinMode(12, INPUT); digitalWrite(12, HIGH); // 12-Kugel, 13-Pfanne
lcd.begin(16, 2);
btSerial.begin(9600);
btSerial.println("bluetooth available");
pinMode(ledPin,OUTPUT);
}
void loop(){
switch (Z) {
case 0: // Aufbau-Info
lcd.clear();
lcd.setCursor(0,0); lcd.print("Kugel einhaengen");
lcd.setCursor(0,1); lcd.print("Pfanne anheben");
delay(4000);
Z=1;
break;
case 1: // Aufbau-Test
lcd.clear();
lcd.setCursor(0,0); lcd.print("Kugel Pfanne");
lcd.setCursor(0,1); lcd.print("Select: weiter");
while (read_LCD_buttons()!=4){
lcd.setCursor(6,0);
if (digitalRead(12)==LOW) lcd.print("+");
else lcd.print("-");
lcd.setCursor(15,0);
if (digitalRead(13)==HIGH) lcd.print("+");
else lcd.print("-");
}
Z=2;
break;
case 2: // Aufbau-Info
lcd.clear();
lcd.setCursor(0,0); lcd.print("Messung starten!");
while (digitalRead(12)==LOW){};
zeit=millis();
while (digitalRead(13)==HIGH){};
zeit=millis()-zeit;
Z=3;
break;
case 3:
lcd.clear();
lcd.setCursor(0,0); lcd.print("Zeit (ms): ");
lcd.setCursor(11,0); lcd.print(zeit);
lcd.setCursor(0,1); lcd.print("Reset ?");
Z=4;
break;
case 4:
break;
}
}
int read_LCD_buttons() { // liest den analogen Eingang 0 und
adc_key_in = analogRead(0); // und gibt eine Ganzzahl zurück
if (adc_key_in > 1000) return 5; // btnNONE
if (adc_key_in < 50) return 0; // btnRIGHT
if (adc_key_in < 250) return 1; // btnRIGHT
if (adc_key_in < 450) return 2; // btnDOWN
if (adc_key_in < 650) return 3; // btnLEFT
if (adc_key_in < 850) return 4; // btnSELECT
return 5; // when all others fail, return this...
}
MIT App Inventor2:
in attachment
My problem now is that I dont know how I can read out the time (in ms) and send it to the Smartphone. Dou you have any advise for me?
With best regards
playzocker22
(I am from Germany, if you have any language questions regarding the sketch just ask)