peony3000

Arduino for Han

Mar 14th, 2012
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1.  
  2.  
  3. #include <SoftwareSerial.h>
  4. SoftwareSerial mySerial = SoftwareSerial(255, 6);
  5.  
  6.   int potentiometerValue01 = 0;
  7.   int potentiometerValue02;
  8.   int potentiometerValue03;
  9.   int potentiometerValue04;
  10.   int potentiometerValue05;
  11.   int potentiometerValue06;
  12.   int lifeExpectancy;
  13.  
  14. void setup() {
  15.  
  16.   pinMode(6, OUTPUT);
  17.   digitalWrite(6, HIGH);
  18.   Serial.begin(9600);
  19.   mySerial.begin(9600);
  20.   mySerial.write(17);                 // Turn backlight on
  21. }
  22.  
  23. void loop() {
  24.   // read the potentiometers
  25.   potentiometerValue01 = analogRead(0);
  26.   //Serial.println("potentiometerValue01 = "+potentiometerValue01);
  27.   delay(100);
  28.   potentiometerValue02 = analogRead(1);
  29.   //Serial.println("potentiometerValue02 = "+potentiometerValue02);
  30.   delay(100);
  31.   potentiometerValue03 = analogRead(2);
  32.   //Serial.println("potentiometerValue03 = "+potentiometerValue03);
  33.   delay(100);
  34.   potentiometerValue04 = analogRead(3);
  35.   //Serial.println("potentiometerValue04 = "+potentiometerValue04);
  36.   delay(100);
  37.   potentiometerValue05 = analogRead(4);
  38.   Serial.println("potentiometerValue05 = "+potentiometerValue05);
  39.   delay(100);
  40.   potentiometerValue06 = analogRead(5);
  41.   //Serial.println("01 02 03 04 05 06 = "+potentiometerValue01+" "+potentiometerValue02+" "+potentiometerValue03+" "+potentiometerValue04+" "+potentiometerValue05+" "+potentiometerValue06);
  42.  
  43.   lifeExpectancy = (potentiometerValue01 + potentiometerValue02 + potentiometerValue03 + potentiometerValue04 + potentiometerValue05 + potentiometerValue06)/24;
  44.  
  45.   // mySerial.write(212);                // Quarter note
  46.   // mySerial.write(220);                // A tone
  47.   // write the message
  48.   delay(100);
  49.   mySerial.write(12);                 // Clear            
  50.   //mySerial.write(17);                 // Turn backlight on
  51.   delay(5);                           // Required delay
  52.   mySerial.print("Life:");  // First line
  53.   mySerial.write(13);                 // Form feed
  54.   mySerial.print(lifeExpectancy);   // Second line
  55.   delay(500);                        // Wait 3 seconds
  56.   //mySerial.write(18);    // Turn backlight off
  57. }
Advertisement
Add Comment
Please, Sign In to add comment