Created
December 16, 2012 01:07
-
-
Save dmd/4301804 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include <LCD.h> | |
#include <LiquidCrystal_I2C.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define I2C_ADDR 0x3F | |
#define BACKLIGHT_PIN 3 | |
#define En_pin 2 | |
#define Rw_pin 1 | |
#define Rs_pin 0 | |
#define D4_pin 4 | |
#define D5_pin 5 | |
#define D6_pin 6 | |
#define D7_pin 7 | |
#define ESTOP_PIN 2 | |
#define TEMP_PIN 0 | |
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin); | |
float LM35_temp() | |
{ | |
return 110 * (float) analogRead(TEMP_PIN) / 1024; | |
} | |
char stemp[10]; | |
void setup() | |
{ | |
estop = false; | |
pinMode(ESTOP_PIN, INPUT_PULLUP); | |
analogReference(INTERNAL); | |
Serial.begin(9600); | |
lcd.begin(20, 4); | |
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE); | |
lcd.setBacklight(HIGH); | |
lcd.home(); | |
lcd.print("InMotion Robot v4"); | |
lcd.setCursor(0, 1); | |
lcd.print("System Operational"); | |
lcd.setCursor(0, 3); | |
lcd.print("Temperature: "); | |
} | |
unsigned long i = 0; | |
unsigned long starttime = 0; | |
void loop() | |
{ | |
i++; | |
if (millis() % 500 == 0) { // silly to update more than 2Hz | |
dtostrf(LM35_temp(), 6, 1, stemp); | |
Serial.println(stemp); | |
Serial.println(i); | |
lcd.setCursor(13, 3); | |
lcd.print(stemp); | |
lcd.setCursor(9, 2); | |
lcd.print((millis() - starttime) / 1000); | |
} | |
if (estop && digitalRead(ESTOP_PIN) == LOW) { | |
estop = !estop; | |
lcd.setCursor(0, 2); | |
lcd.print("STOPPED: "); | |
starttime = millis(); | |
} else if (!estop && digitalRead(ESTOP_PIN) == HIGH) { | |
estop = !estop; | |
lcd.setCursor(0, 2); | |
lcd.print("RUNNING: "); | |
starttime = millis(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment