code.txt

Download code.txt

If you can't read please download the document

Upload: jared-hancock

Post on 08-Nov-2015

225 views

Category:

Documents


2 download

TRANSCRIPT

/*unRaidLCD.inoCODE UPDATED 22/10/2014A little program to display uptime and 4 temperature sensor valueThe Circuit:LCD n SymbolFunction connectionPin1VssDisplay power ground & 10k Potentiometer Ground (pin 1)ground (either black wire)2VddDisplay power +5V & 10k Potentiometer pin 1) +5v (red wire)3VoContrast Adjust. (Wiper (pin 2) on 10k Potentiometer pin 2)4RSRegister select Arduino digital pin 75R/WData read/write ground (either black wire)6EEnable strobe Arduino digital pin 67DB0Data Bus 0 N/C8DB1Data Bus 1 N/C9DB2Data Bus 2 N/C10DB3Data Bus 3 N/C11DB4Data Bus 4 Arduino digital pin 512DB5Data Bus 5 Arduino digital pin 413DB6Data Bus 6 Arduino digital pin 314DB7Data Bus 7 Arduino digital pin 215ALED backlight +5v+5v (red wire)16KLED backlight groundground (either black wire)Temperature Sensors: (Centre pin connection)CPU Arduino pin A0SYS Arduino pin A1Parity Arduino pin A2Drive Arduino pin A3+5v connected to A5 to act as voltage reference for analog calculationsD8 Buzzer 2secs on 1 sec offD10 LED normally on fade in and out if alarmD11 5v Input to activate Battery Backup warning message 5v input to activate message on screen connect Ground to a 1k resistor to D11 keep pin lowThis stops the message activating on screen (keeps D11 low and when 5v to D11 make the pin high which activates message*/// include the required libraries#include #include // Defined constant values#define LCD_D0 5 // LCD Data pin 0#define LCD_D1 4 // LCD Data pin 1#define LCD_D2 3 // LCD Data pin 2#define LCD_D3 2 // LCD Data pin 3#define LCD_EN 6 // PWM pin for LCD Enable#define LCD_RS 7 // LCD RS pin#define VREF 27 // Voltage ref analog input D9#define BUZZPIN 8 // pin for buzzer#define LEDPIN 10 // pin for led#define BACKUP 11 // pin for Battery Backup indicator 5v input to activate message on screen connect 1k resistor from ground to pin D11 to keep pin low#define DISPLAY_WIDTH 20 // width of display#define DISPLAY_HEIGHT 4 // height of display#define BUFSIZ 16 // Maximum size of smoothing buffer#define BUFUSE 16 // Number to use for smoothing (must be < BUFSIZ)#define NUMADC 4 // Number of values to display#define FLIP_TIME 4 // nr. secs to wait before screen change#define flipdelay 5000 // 5 second delay needed to change display_flip variable#define BBdelay 6000 // 2 second delay interval for backup battery screen// initialize the lcd library with the numbers of the interface pinsLiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D0,LCD_D1,LCD_D2,LCD_D3);static float voltage_ref=5.00; // Voltage reference value (will be overwritten by input reading)int brightness=0; // Current LED brightnessint fadeAmount = 5; // how many points to fade the LED bychar str[22];boolean shown = false, scrToggle = false, StartReadings = false;static int display_flip=0;unsigned long timer = 0, BB_timer = 0; // X// ============================================================================================================// Structure to define the sensors, text, text positions, value positions and smoothing buffer//// pin Analog input to read (A0 or A1 etc.)// txt up to TXTSIZ characters to display// type c=temperature, v-millivolts otherwise %// txtx,txty where to start the text// fmt format string for display of value// valx,valy where to display the value// ck 1 if alarm checks required, 2 if value to be output on alarm// lo low limt alarm value// hi High limit alarm value// alarm result of alarm test (0 no alarm, 1=below low limit, 2=above high limit)// lotxt text for alarm low (make this an even number of characters)// hitxt text for alarm high (make this an even number of characters)// bufptr internal buffer pointer for smoothing// buffer internal buffer//// ============================================================================================================struct {int pin;char *txt;char type;uint8_t txtx,txty;char *fmt;uint8_t valx,valy;int ck,lo,hi;uint8_t alarm;char *lotxt,*hitxt;uint8_t bufptr;int buffer[BUFSIZ];}sensors[NUMADC] ={A0, " CPU ", 'c', 0,2, "%3dc", 4,2, 1, 0, 105, 0, "CPU Temp Lo","CPU Temp Hi", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 105 = 65C OR 90 = 55CA1, " SYS ", 'c', 10,2, "%3dc", 15,2, 1, 0, 78, 0, "SYS Temp Lo","SYS Temp Hi", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //78 = 50CA2, "PARITY ", 'c', 0,3, "%3dc", 6,3, 1, 0, 94, 0, "PARITY Temp Lo","PARITY Temp Hi", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 94 = 60CA3, " DRIVE ", 'c', 10,3, "%3dc", 16,3, 1, 0, 94, 0, "DRIVE Temp Lo","DRIVE Temp Hi", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 // 94 = 60C};// ============================================================================================================// Setup routine only runs once at power up// ============================================================================================================void setup(){pinMode(BUZZPIN, OUTPUT); // set a pin for buzzer outputpinMode(LEDPIN, OUTPUT); // set a pin for led outputanalogWrite(LEDPIN,255); // Switch the LED on//Serial.begin(9600); // Start the serial connection with the computer to view the result open the serial monitorlcd.begin(DISPLAY_WIDTH, DISPLAY_HEIGHT); // set up the LCD's number of columns and rows:lcd.clear(); // Clear the LCD.lcd.setCursor((DISPLAY_WIDTH-7)/2,0);lcd.print(" Admin"); // Print out a title while we wait for the analog smoothing to initialiselcd.setCursor(0,1);lcd.print(" Peter Birkett"); //setTime(0,0,0,1,1,1970); // set the time to 1/1/1970 00:00:00 - where the time functions start frompinMode(VREF,INPUT); // Make sure the voltage reference is an inputpinMode(BACKUP,INPUT); // Set the Battery Backup Pin as an Inputdelay(100); // Let the input switching settlegetVref(); // read the voltage reference valuefor(uint8_t i=0; i= flipdelay){timer = millis();getVref(); // read the voltage reference valuedisplay_flip=(display_flip+1)&1; // either 1 or zero each time through this routineif (display_flip==1){lcd.setCursor(0,0);lcd.print(" unRaid Server ");lcd.setCursor(0,1);lcd.print(" 192.168.0.7 ");}else{lcd.setCursor(0,0);lcd.print(" Server Uptime ");}// display the value titlesif(!shown){for (uint8_t i=0; i