first commit

first commit

error: pathspec 'Led_fixture_sec.ino' did not match any file(s) known to git

--- Led_fixture_sec.ino
+++ Led_fixture_sec.ino
@@ -0,0 +1,1933 @@
+// versija
+// v. 1.0 - pievienoju visus LED kanalus regulesanai
+// 2014.03.30 v. 1.1 - pievienoju individulos kanalu taimerus
+// 2014.06.20 v. 1.2 - partaisiju DIMMeasanu uz 1 sekundes intervalu
+// 2014.07.19 v. 2.0 - izlaboju lielu kludu DIMMesanas algoritma, pieliku DIMM rezima indikaciju
+
+// ~/Documents/Arduino/350W LED Fixture LDD/led_fixture
+
+// This is for compatibility with both arduino 1.0 and previous versions
+#if defined(ARDUINO) && ARDUINO >= 100
+#include "Arduino.h"
+#else
+#include "WProgram.h"
+#endif
+
+
+// aquacontroller PIN
+/* Digital In.Out
+  1
+  2 - Night LED PWM Light
+
+  3 - LED
+  4 - LED
+  5 - LED
+  6 - LED
+
+  7 - LED Royal Blue
+  8 - LED Blue
+  9 - LED Royal Blue ..
+ 10 - LED White
+
+ 11 - PWM Encoder A
+ 12 - PWM Encoder B
+
+ 13 - PWM LCD Screen background
+
+ 20 - I2C SDA
+ 21 - I2C SCL
+
+ 23 - Keyboard cols 1
+ 24 - Keyboard cols 2
+ 25 *
+ 26 - Keyboard cols 3
+ 27 - Keyboard rows 1
+ 28 - 1-Wire Datas Thermometer
+ 29 - Keyboard rows 2
+
+ 30 - Fan on/off
+ 32
+
+ 46 - LCD CSB (38)
+ 48 - LCD RS (39)
+ 50 - LCD CLK (29)
+ 52 - LCD SI (28)
+
+ Analog PIN
+ 3 - Current Sensor 1
+ 4 - Current Sensor 2
+ 14 - Voltage sensor 1
+ 15 - voltage sensor 2
+ */
+
+// *********************************************************************************************
+//            EPROM Memory
+// *********************************************************************************************
+#include <EEPROM.h>
+
+
+// *********************************************************************************************
+//            Temperature
+// *********************************************************************************************
+//#include <OneWire.h>
+/*
+#include <DallasTemperature.h>
+
+// Data wire is plugged into pin 28 on the Arduino
+#define ONE_WIRE_BUS 28
+
+// Setup a oneWire instance to communicate with any OneWire devices
+// (not just Maxim/Dallas temperature ICs)
+OneWire oneWire(ONE_WIRE_BUS);
+
+// Pass our oneWire reference to Dallas Temperature.
+DallasTemperature sensors(&oneWire);
+*/
+float temp[]={0,0,0};
+int temp_counter=0;
+unsigned long temp_time=0;
+int temperature_mode=0; // temp screen modes 0-hide, 1-show [1] 10,2
+
+
+#include <OneWire.h>
+OneWire  ds(28);
+
+// *********************************************************************************************
+//            Voltage values
+// *********************************************************************************************
+// variables for input pin and control LED
+
+
+  float vout = 0.0;
+  float vin = 0.0;
+  float R1 = 1000000.0;    // !! resistance of R1 !!
+  float R2 = 100000.0;     // !! resistance of R2 !!
+
+  float volt[]={24,48}; // get nominal default
+
+  int volt_sensot_PIN[] ={15,14};
+  int volt_sensor_value = 0;
+
+// For Current sensor
+
+int A1_pin=3;
+int A2_pin=4;
+
+int currentSens1=0;
+int currentSens2=0;
+
+int CurrentValue1=0;
+int CurrentValue2=0;
+float amps1=0;
+float amps2=0;
+
+
+// *********************************************************************************************
+//            Rotary encoder
+// *********************************************************************************************
+// A -> pin 11 (need PWM)
+// B -> pin 12 (need PWM)
+#include <QuadEncoder.h>
+QuadEncoder qe(12,11);
+int qe1Move=0;
+
+
+// *********************************************************************************************
+//            Keypad
+// *********************************************************************************************
+#include <Keypad.h>
+const byte ROWS = 2; // 2 rows
+const byte COLS = 3; // 3 columns
+// Define the Keymap
+char keys[ROWS][COLS] = {
+  {'1','2','a'  },
+  {'3','4','b'  }
+};
+
+byte rowPins[ROWS] = {27, 29 };         // Connect keypad rows.
+byte colPins[COLS] = {23, 25, 26 };     // Connect keypad columns.
+
+// Create the Keypad
+Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
+
+// pogu kodi -> 2, 4, 1, 3, [a], b, RESET
+//                        encoder
+
+// *********************************************************************************************
+//            Timer RTC 1307
+// *********************************************************************************************
+
+
+#include <Wire.h>  // Incluye la librería Wire
+#include <DS1307.h> // written by  mattt on the Arduino forum and modified by D. Sjunnesson
+
+// global date parameter
+int hour = 0;
+int second = 0;
+int minute = 0;
+int monthDay = 0;
+int month = 0;
+int year = 0;
+
+int flash_timer=0;
+
+// koordinates laika un datuma iestadisanai
+int date_line[]={ 1, 1, 1, 2, 2, 2};
+int date_pos[]= { 4, 7,10, 3, 8,11};
+int date_mode=0; // kura pozicija atrodas kursots mainot datumu
+
+int timer_line[]={ 1, 1, 1, 1, 2};
+int timer_pos[]= { 5, 8,11,14, 8};
+int timer_mode=0; // kura pozicija atrodas kursots mainot taimeru
+
+int temp_line[]={ 1, 1};
+int temp_pos[]= { 4, 13};
+int temp_mode=0; // kura pozicija atrodas kursots mainot taimeru
+
+// ventilatora izvads
+int pinFan = 30;
+int fan_on=0; //ReadEEPROM(9);
+int fan_off=0;
+int FAN_status=0;
+
+
+int oSec=0;
+
+
+// koordinates screen saver rezima LRD knalu statusiem
+int LED_line[]={ 1, 1, 1, 1, 2, 2, 2, 2};
+int LED_pos[]= { 1, 5, 9,13, 1, 5, 9,13};
+
+
+
+// gaismas taimeri
+int on_h[]=  {15,18,15,18, 0, 1, 2, 3};
+int on_m[]=  { 0, 0, 0, 0, 0, 0, 0, 0};
+int off_h[]= {23,20,23,20, 1, 2, 3, 4};
+int off_m[]= { 0, 0, 0, 0, 0, 0, 0, 0};
+// sunset taimeri
+int sunset[]={10,10,10,10,10,10,10,10};
+
+float t; // temporary value for second dimming
+
+// *********************************************************************************************
+//            DOG-M LCD Display
+// *********************************************************************************************
+#include <DogLcd.h>
+
+// initialize the library with the numbers of the interface pins
+DogLcd lcd(31, 33, 37, 35); //SI, CLK, RS, CSB
+int lcd_pin=13; // LCD background LED pin
+
+// custom Character for DOGM 16x3 display
+byte progress[8] = {  B00000,  B11011,  B11011,  B11011,  B11011,  B11011,  B00000}; // ||
+byte     pro1[8] = {  B00000,  B11000,  B11000,  B11000,  B11000,  B11000,  B00000}; // |.
+byte     pro2[8] = {  B00011,  B00011,  B00011,  B00011,  B00011,  B00011,  B00011}; // .|
+byte    proto[8] = {  B11111,  B11111,  B11111,  B11111,  B11111,  B11111,  B11111}; //|||
+byte       l1[8] = {  B11111,  B11011,  B10101,  B10101,  B10001,  B10101,  B11111}; //A
+byte       l2[8] = {  B11111,  B10011,  B10101,  B10011,  B10101,  B10011,  B11111}; //B
+byte       l3[8] = {  B11111,  B11011,  B10101,  B10111,  B10101,  B11011,  B11111}; //C
+byte       l4[8] = {  B11111,  B10011,  B10101,  B10101,  B10101,  B10011,  B11111}; //D
+
+byte       l5[8] = {  B11111,  B10001,  B10111,  B10011,  B10111,  B10001,  B11111}; //E
+byte       l6[8] = {  B11111,  B10001,  B10111,  B10011,  B10111,  B10111,  B11111}; //F
+byte       l7[8] = {  B11111,  B11001,  B10111,  B10101,  B10101,  B11001,  B11111}; //G
+byte       l8[8] = {  B11111,  B10101,  B10101,  B10001,  B10101,  B10101,  B11111}; //H
+
+// menu bar
+byte      br[8] = {  B00000,  B00000,  B11011,  B11011,  B00000,  B00000,  B00000}; // ||
+byte     pr1[8] = {  B11000,  B11000,  B11011,  B11011,  B11000,  B11000,  B00000}; // |.
+byte     pr2[8] = {  B00011,  B00011,  B11011,  B11011,  B00011,  B00011,  B00000}; // .|
+
+
+
+// *********************************************************************************************
+//            Mani mainigie
+// *********************************************************************************************
+
+int interval = 100;// interval at which to blink (milliseconds)
+long previousMillis = 0;        // will store last time Data was updated
+
+long interval2 = 1000; // intervals taimeru darbibai
+long previousMillis2 = 0;
+unsigned long currentMillis=0; //timers
+int null=0;
+
+// mainigie prieks menu
+char* menu_text[] ={
+  "LED A",        //1
+  "LED B", //2
+  "LED Moon",        //3
+  "Temperature",         //4
+  "Setup",    //5
+  "Date/Time", //6
+  "Manual mode", //7
+
+  "White",  //8
+  "Royal Blue..", //9
+  "Blue", // 10
+  "Royal Blue.", //11
+  "Green", //12
+  "UV", //13
+  "Red", //14
+  "Royal Blue", //15
+
+  "Reserved" // 16
+};
+
+int menu_id[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
+
+int menu_pos=0;
+int menu_old=-1;
+int menu_size =(sizeof(menu_text)/sizeof(char *))-1;
+int menu_mode=0;
+
+
+String txt;
+int flash=0;
+int flash_stat=0;
+int flash_pos;
+int flash_line;
+String flash_txt;
+int timeout=0;
+
+char Button; // last pressed button;
+char key;
+
+int lcd_max=255; // max LCD bright
+int lcd_min=50;  // min (darknes) :CD bright -> go to screen slip mode
+
+
+
+// DIMM kanalu mainigie
+// white, Royal Blue.., Blue, Royal Blue.,
+// Red, Green, UV, Royal Blue
+
+int DIMM_pin[]=   { 10,  9,  8,  7,  6,  5,  4,  3, 2};
+int DIMM_value[]= { 76,128,220,150, 20,100,200, 36, 128};
+int DIMM_actual[]={  0,  0,  0,  0,  0,  0,  0,  0, 128};
+int DIMM_temp[]=  { -1, -1, -1, -1, -1, -1, -1, -1, -1};
+
+int sunset_actual[]={  0,  0,  0,  0,  0,  0,  0,  0, 0};
+
+int DIMM_tmp[]=   { 0, 0, 0, 0, 0, 0, 0, 0, 0};
+int DIMM_status[]={ 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+// koordinates uz ekrana bar attelosahani
+int dimmP[]={0,0,8,8};
+int dimmL[]={1,2,1,2};
+
+
+// kanalu krasas nosaukums
+char* DIMM_text[] ={
+  "White",        //1
+  "RB ..", //2
+  "Blue",        //3
+  "RB .",         //4
+  "Green",    //5
+  "UV",
+  "Red",
+  "RB",
+  "LED Moon"
+};
+
+
+
+int DIMM_active=0;
+int DIMM_value_0ld;
+int DIMM_increment_B=8.5;     //solis liela grafika dimmesanai
+int DIMM_increment_S=18.2;    //solis mazaa grafika dimmesanai
+int DIMM_increment=0;         // tekoshais solis
+int cha=0; // tekoshais kanaals reguleeshana
+
+int char_small_step=char(165);
+int char_big_step=char(161);
+int cha_incr=0; // otram ranalu komplektam jabut 4
+
+int hour2 = 0;
+int minute2 = 0;
+int second2 = 0;
+int manual_on=2; // mode
+
+// *****************************************************************************************
+void setup() {
+  Wire.begin(); // Establece la velocidad de datos del bus I2C
+  Serial.begin(9600);
+
+// pin modes
+  pinMode(lcd_pin, OUTPUT);
+  pinMode(pinFan, OUTPUT);
+
+  for (int i=0; i<=8; i++){
+    pinMode(DIMM_pin[i], OUTPUT);
+  }
+
+
+
+
+  // set up the LCD
+  lcd.begin(DOG_LCD_M163, 0x27); // contrast from 0x1A to 0x28
+  analogWrite(lcd_pin, lcd_max);  // set LCD display background light to maximum
+
+  // create custom char
+  lcd.createChar(0, progress);
+  lcd.createChar(1, pro1); // <
+  lcd.createChar(2, pro2); // >
+  lcd.createChar(3, proto); // | lcd.write(3);
+  lcd.createChar(4, l1);
+  lcd.createChar(5, l2);
+  lcd.createChar(6, l3);
+  lcd.createChar(7, l4);
+
+  // additional display settings
+  lcd.home(); // need before use custom char
+  lcd.noCursor();
+  lcd.noAutoscroll();
+
+
+  // Print a message to the LCD.
+  //lcd.print("LED Light");
+  ShowMenu();
+
+  RTC.stop();
+  RTC.start();
+
+  // load chanel data
+  for (int i=0; i<=7; i++){ //0-7 LED
+    ReadEEPROM(i);
+  }
+ ReadEEPROM(8); // load moon data
+ ReadEEPROM(9); // load fan temperature data
+
+  SetMenu();
+
+}
+// *********************************************************************************************
+//            L O O P
+// *********************************************************************************************
+
+
+void loop() {
+  // input devices scan
+  // encoder
+  qe1Move=qe.tick();
+
+  // keypad
+  key = kpd.getKey();
+  Button = ' ';
+  if(key) { // same as if (key != NO_KEY)
+    Button=key;
+    Pogas ();
+    timeout=0;
+
+    Serial.println(Button);
+
+  }
+  if (qe1Move=='>') timeout=0;
+  if (qe1Move=='<') timeout=0;
+
+
+  if (Button=='b') { // go to main menu
+    lcd.clear();
+    temperature_mode=0;
+    flash=1;
+    menu_old=-1;
+    menu_mode=0;
+    SetMenu();
+    ShowMenu();
+
+    analogWrite(lcd_pin, lcd_max);
+  }
+
+  if (Button=='1') { // set screensaver active
+    timeout=timeout+51;
+    menu_mode=0;
+    flash=2;
+    lcd.clear();
+   // lcd.setCursor(4, 0);
+   // lcd.print("Reef LED");
+    analogWrite(lcd_pin, lcd_min);
+  }
+
+  if (Button=='2') { // manual modes
+      manual_on++;
+      if (manual_on>2) manual_on=0;
+      manual_modes_show();
+  }
+
+
+
+
+// mode switch section
+    if (menu_mode==0) {
+        Menu();
+        if (Button=='a') { // encoder button
+          flash=0;
+          menu_mode=menu_pos+1;
+          lcd.clear();
+          if (menu_mode==1) {// color A
+            Set1();
+            cha_incr=0;
+            temperature_mode=3;
+            DimmingStart();
+          }
+          if (menu_mode==2) {// color B
+            Set2();
+            cha_incr=4;
+            temperature_mode=3;
+            DimmingStart();
+          }
+          if (menu_mode==3) {// moon light
+            SetBar();
+            DimmingBIGStart();
+            temperature_mode=3;
+            timer_mode=0;
+          }
+
+
+          if (menu_mode==4) { // temperature settup
+            lcd.setCursor(0, 0);
+            lcd.print(flash_txt);
+
+            temperature_mode=1;
+            temp_mode=0;
+            printTemp();
+          }
+
+
+          if (menu_mode==6) { // date/time
+            lcd.setCursor(0, 0);
+            lcd.print(flash_txt);
+            temperature_mode=3;
+            date_mode=0;
+            printTimeOnly();
+          }
+
+          if (menu_mode>=8 && menu_mode<=15) {
+            SetBar();
+            temperature_mode=3;
+            DimmingBIGStart();
+            timer_mode=0;
+          }
+        }
+    } else if (menu_mode==-2) { // screen saver
+      // nope
+    } else if (menu_mode==1 || menu_mode==2) {                 // dimming main color menu
+      Dimming();
+    } else if (menu_mode==3) {                // LED Moon settup
+        cha=8;
+        Dimming_big();
+    } else if (menu_mode==4) {                                 // set temperature mode
+      SetTemp();
+    } else if (menu_mode==6) {                                 // set date/time mode
+      SetDateTime();
+    } else if (menu_mode>=8 || menu_mode<=15) {                // individual chanel setup
+        cha=menu_mode-8;
+        Dimming_big();
+    } else {
+      // nope
+}
+
+
+
+
+
+
+  if (timeout>50 && menu_mode==0) {   // iesledzas screensaver
+    flash=2;
+    menu_mode=-2;
+    lcd.clear();
+   // lcd.setCursor(4, 0);
+   // lcd.print("Reef LED");
+    analogWrite(lcd_pin, lcd_min);
+    SetBar();
+  }
+
+
+  // run only one time in interval
+  currentMillis = millis();
+  if(currentMillis - previousMillis > interval) {
+    previousMillis = currentMillis;
+
+    Flash();
+  }
+
+
+  if(currentMillis - previousMillis2 > interval2) {
+    previousMillis2 = currentMillis;
+
+    Watch(); // aizejam uz taimeriem
+    Termo();
+    Voltage(); // skatamies Voltus uz barosanas blokiem
+    PrintStatus(); // drukajam uz ekrana parametrus
+  }
+
+
+
+
+}
+
+// *********************************************************************************************
+//            Manas apaksh proceduras
+// *********************************************************************************************
+String toDouble(int a){
+  if (a<10) return "0"+String(a);
+  return String(a);
+}
+
+String toTriple(int a){
+  if (a<10) return "00"+String(a);
+  if (a<100) return "0"+String(a);
+  return String(a);
+}
+
+
+// *********************************************************************************************
+//            Manas proceduras
+// *********************************************************************************************
+
+// *********************************************************************************************
+//            Ekrana 2 pedeju liniju attirisana
+// *********************************************************************************************
+
+void Set1(){ // set A B C D
+  lcd.createChar(4, l1);
+  lcd.createChar(5, l2);
+  lcd.createChar(6, l3);
+  lcd.createChar(7, l4);
+  lcd.home();
+ SetBar();
+
+}
+
+void Set2(){ // set E F G H
+  lcd.createChar(4, l5);
+  lcd.createChar(5, l6);
+  lcd.createChar(6, l7);
+  lcd.createChar(7, l8);
+  lcd.home();
+  SetBar();
+}
+
+void SetMenu(){ // progress bar set to Main menu style
+  lcd.createChar(0, br);
+  lcd.createChar(1, pr1);
+  lcd.createChar(2, pr2);
+  lcd.home();
+}
+
+void SetBar() { // progress bar sey to LED DIMMING style
+  lcd.createChar(0, progress);
+  lcd.createChar(1, pro1); // <
+  lcd.createChar(2, pro2); // >
+  lcd.home();
+}
+
+
+void CLS() {
+  lcd.setCursor(0, 1);
+  lcd.print("                ");
+  lcd.setCursor(0, 2);
+  lcd.print("                ");
+}
+
+
+
+
+// *********************************************************************************************
+//            MENU
+// *********************************************************************************************
+
+
+void Menu(){ // ja menu ir 0 tad sheit parsledzam ar enkoderu menu poziciju
+  if (qe1Move=='>') {
+    menu_pos++;
+    if (menu_pos>menu_size) menu_pos=0;
+    ShowMenu();
+  }
+  else if (qe1Move=='<') {
+    menu_pos--;
+    if (menu_pos<0) menu_pos=menu_size;
+    ShowMenu();
+  }
+
+}
+
+
+// *********************************************************************************************
+//            Show Menu
+// *********************************************************************************************
+
+
+void ShowMenu(){
+  if (menu_pos!=menu_old){
+    flash_line=1;
+    lcd.setCursor(0, flash_line); // poz, rinda
+    lcd.print("<              >");
+
+    // show menu scrollbar
+    /*
+    lcd.setCursor((15-menu_size)/2,2); // poz, rinda
+    for (int i=0; i<=menu_size; i++){
+      if (i!=menu_pos) {
+        lcd.print(".");
+      }
+      else {
+        lcd.write(161);
+      }
+    }
+*/
+    MenuPos(menu_size, menu_pos);
+
+
+    flash_txt=menu_text[menu_pos];
+    flash_pos=(16-flash_txt.length())/2;
+    menu_old=menu_pos;
+    flash=1;
+  }
+}
+
+
+
+void MenuPos(int a, int b) {// a cik kopa, b= kura vieta
+  int d;
+  int d2=a/2;
+  d=1+(16-(a/2))/2;
+  d=d-1;
+
+
+  for (int i=0; i<= d2; i++){
+    lcd.setCursor(d+i, 2);
+    lcd.write(null);
+  }
+  if (b+d!=b-1) {
+    lcd.setCursor(d+(b/2), 2);
+    if ( (b % 2) == 0) {
+      lcd.write(1);
+    }
+    else {
+      lcd.write(2);
+    } //2
+  }
+/*
+  if (b+d+1!=b+15) { // 7 cik zimigas pozicijas aiznjem BAR
+    lcd.setCursor(b+d+1, c);
+    lcd.write(" ");
+  }
+*/
+
+}
+
+
+
+// *********************************************************************************************
+//            Flash text
+// *********************************************************************************************
+
+void Flash(){
+  if(flash==1){
+    int ln=flash_txt.length();
+    if (flash_stat==0) {
+      flash_stat++;
+      lcd.setCursor(flash_pos, flash_line);
+      for (int i=0; i<=ln-1; i++){
+        lcd.print(" ");
+      }
+      // palielinam intervalu
+      timeout++;
+      //  lcd.setCursor(0, 2);
+      //  lcd.print(timeout);
+    }
+    else {
+      lcd.setCursor(flash_pos, flash_line);
+
+
+      if (menu_mode==1 || menu_mode==2) {
+        lcd.write(cha+4);
+      } else if (menu_mode>=8 && menu_mode<=15) {
+        if (timer_mode==0){
+          lcd.write(3);
+        } else {
+          lcd.print(flash_txt);
+        }
+      } else if (menu_mode==3) {
+          lcd.write(3);
+      } else {
+        lcd.print(flash_txt);
+      }
+      flash_stat++;
+      if (flash_stat>4) flash_stat=0;
+    }
+  }
+  if (flash==2){ // iesl'dzas screensacer
+    //printTime();
+    //printActualA();
+  }
+
+}
+
+// *********************************************************************************************
+//            Print Actual
+// *********************************************************************************************
+
+
+void printActualA(){
+  //  int hr = RTC.get(DS1307_HR,true);
+  //  int mn = RTC.get(DS1307_MIN,false);
+  //  int sc = RTC.get(DS1307_SEC,false);
+    /*
+    lcd.setCursor(4, 0);
+    lcd.print(toDouble(hour));
+    lcd.print(":");
+    lcd.print(toDouble(minute));
+    lcd.print(":");
+    lcd.print(toDouble(second));
+ */
+
+    lcd.setCursor(0, 1);
+    lcd.write(4);
+    BarS(DIMM_actual[0],1,1);
+
+    lcd.setCursor(0, 2);
+    lcd.write(5);
+    BarS(DIMM_actual[1],1,2);
+
+    lcd.setCursor(8, 1);
+    lcd.write(6);
+    BarS(DIMM_actual[2],9,1);
+
+    lcd.setCursor(8, 2);
+    lcd.write(7);
+    BarS(DIMM_actual[3],9,2);
+
+
+}
+
+
+
+// *********************************************************************************************
+//            Print time
+// *********************************************************************************************
+
+void printTime(){
+  flash_timer++;
+  // DateTime now = RTC.now(); // Obtiene la fecha y hora del RTC
+  if (flash_timer<=6) {
+    hour = RTC.get(DS1307_HR,true);
+    minute = RTC.get(DS1307_MIN,false);
+    second = RTC.get(DS1307_SEC,false);
+    monthDay =RTC.get(DS1307_DATE,false);
+    month = RTC.get(DS1307_MTH,false);
+    year = RTC.get(DS1307_YR,false);
+    lcd.setCursor(4, 1);
+    lcd.print(toDouble(hour));
+    lcd.print(":");
+    lcd.print(toDouble(minute));
+    lcd.print(":");
+    lcd.print(toDouble(second));
+
+    lcd.setCursor(3, 2);
+    lcd.print(year);
+    lcd.print("-");
+    lcd.print(toDouble(month));
+    lcd.print("-");
+    lcd.print(toDouble(monthDay));
+  }
+  if (flash_timer==7) {
+    flash_timer=0;
+    hour = RTC.get(DS1307_HR,true);
+    minute = RTC.get(DS1307_MIN,false);
+    second = RTC.get(DS1307_SEC,false);
+    lcd.setCursor(4, 1);
+    lcd.print(toDouble(hour));
+    lcd.print(" ");
+    lcd.print(toDouble(minute));
+    lcd.print(" ");
+    lcd.print(toDouble(second));
+  }
+}
+
+
+void printTimeOnly(){
+  hour = RTC.get(DS1307_HR,true);
+  minute = RTC.get(DS1307_MIN,false);
+  second = RTC.get(DS1307_SEC,false);
+  monthDay =RTC.get(DS1307_DATE,false);
+  month = RTC.get(DS1307_MTH,false);
+  year = RTC.get(DS1307_YR,false);
+  lcd.setCursor(4, 1);
+  lcd.print(toDouble(hour));
+  lcd.print(":");
+  lcd.print(toDouble(minute));
+  lcd.print(":");
+  lcd.print(toDouble(second));
+
+  lcd.setCursor(3, 2);
+  lcd.print(year);
+  lcd.print("-");
+  lcd.print(toDouble(month));
+  lcd.print("-");
+  lcd.print(toDouble(monthDay));
+}
+
+
+// *********************************************************************************************
+//            Pogas - pogu apstr'de
+// *********************************************************************************************
+
+void Pogas() {
+
+
+}
+
+
+
+// *********************************************************************************************
+//            EPROM data save and read
+// *********************************************************************************************
+
+
+void SaveEEPROM(int a){
+  // a light chanel 0 - 7, 8 moon
+
+  if (a<=7){ // save LED chanel
+    EEPROM.write((a*10), on_h[a]);
+    EEPROM.write((1+a*10), on_m[a]);
+    EEPROM.write((2+a*10), off_h[a]);
+    EEPROM.write((3+a*10), off_m[a]);
+    EEPROM.write((4+a*10), sunset[a]);
+    EEPROM.write((5+a*10), DIMM_value[a]);
+    Serial.print(a);
+    Serial.print(" save : ");
+    Serial.println(DIMM_value[a]);
+  }
+  if (a==8){// save moon data
+    EEPROM.write(80, DIMM_value[a]);
+  }
+  if (a==9){// save fan data
+    EEPROM.write(81,fan_on);
+    EEPROM.write(82,fan_off);
+  }
+}
+
+void ReadEEPROM(int a){
+  if (a<=7){ // save LED chanel
+    on_h[a] = EEPROM.read(a*10);
+    on_m[a] = EEPROM.read(1+a*10);
+    off_h[a] = EEPROM.read(2+a*10);
+    off_m[a] = EEPROM.read(3+a*10);
+    sunset[a] = EEPROM.read(4+a*10);
+    DIMM_value[a] = EEPROM.read(5+a*10);
+    Serial.print(a);
+    Serial.print(" read : ");
+    Serial.println(DIMM_value[a]);
+  }
+  if (a==8){// load moon data
+    DIMM_value[a] = EEPROM.read(80);
+  }
+  if (a==9){// load fan settings
+    fan_on = EEPROM.read(81);
+    fan_off = EEPROM.read(82);
+
+    Serial.print("temp on : ");
+    Serial.println(fan_on);
+    Serial.print("temp off : ");
+    Serial.println(fan_off);
+
+
+  }
+
+
+}
+
+// *********************************************************************************************
+//            SetTemperature -  iestadisana
+// *********************************************************************************************
+void printTemp() {
+  lcd.setCursor(0, 1);
+  lcd.print("On: ");
+  lcd.print(fan_on);
+  lcd.print((char)223);
+  lcd.setCursor(8, 1);
+  lcd.print("Off: ");
+  lcd.print(fan_off);
+  lcd.print((char)223);
+  lcd.setCursor(1, 2);
+  lcd.print("Current: ");
+  //lcd.print(fan_off);
+  //lcd.print((char)223);
+  //lcd.print("C");
+
+}
+
+
+void SetTemp(){
+  oSec='1111';
+  flash=1;
+  switch (temp_mode) {
+  case 0:
+    flash_txt=toDouble(fan_on);
+    break;
+  case 1:
+    flash_txt=toDouble(fan_off);
+    break;
+  case 2:
+    // set Temperature
+    SaveEEPROM(9);
+    menu_old=-1;
+    menu_mode=0;
+    lcd.clear();
+    temperature_mode=0;
+    SetMenu();
+    ShowMenu();
+    break;
+  }
+  if (temp_mode<2) {
+    flash_line=temp_line[temp_mode];
+    flash_pos=temp_pos[temp_mode];
+    if (Button=='a') {
+      temp_mode++;
+      lcd.setCursor(flash_pos, flash_line);
+      lcd.print(flash_txt);
+    }
+
+  }
+
+  if (qe1Move=='>') {
+    switch (temp_mode) {
+    case 0:
+      fan_on++;
+      if (fan_on>40) fan_on=22;
+      break;
+    case 1:
+      fan_off++;
+      if (fan_off>40) fan_off=22;
+      break;
+    }
+  }
+  else if (qe1Move=='<') {
+    switch (temp_mode) {
+    case 0:
+      fan_on--;
+      if (fan_on<22) fan_on=40;
+      break;
+    case 1:
+      fan_off--;
+      if (fan_off<22) fan_off=40;
+      break;
+    }
+  }
+
+}
+
+
+
+
+
+
+// *********************************************************************************************
+//            SetDateTime - datuma un laika iestadisana
+// *********************************************************************************************
+void SetDateTime(){
+  oSec='1111';
+  switch (date_mode) {
+    case 0:
+    flash=1;
+      flash_txt=toDouble(hour);
+      break;
+    case 1:
+      flash_txt=toDouble(minute);
+      break;
+    case 2:
+      flash_txt=toDouble(second);
+      break;
+    case 3:
+      flash_txt=String(year);
+      break;
+    case 4:
+      flash_txt=toDouble(month);
+      break;
+    case 5:
+      flash_txt=toDouble(monthDay);
+      break;
+    case 6:
+      // set date/time
+      flash=0;
+      RTC.stop();
+      RTC.set(DS1307_SEC,second);        //set the seconds
+      RTC.set(DS1307_MIN,minute);     //set the minutes
+      RTC.set(DS1307_HR,hour);       //set the hours
+      RTC.set(DS1307_DATE,monthDay);       //set the date
+      RTC.set(DS1307_MTH,month);        //set the month
+      RTC.set(DS1307_YR,(year-2000));         //set the year
+
+      RTC.start();
+      // end
+      menu_old=-1;
+      menu_mode=0;
+      lcd.clear();
+      SetMenu();
+      ShowMenu();
+      break;
+  }
+  if (date_mode<6) {
+    flash_line=date_line[date_mode];
+    flash_pos=date_pos[date_mode];
+    if (Button=='a') {
+      date_mode++;
+
+      lcd.setCursor(flash_pos, flash_line);
+      lcd.print(flash_txt);
+    }
+
+  }
+
+  if (qe1Move=='>') {
+    switch (date_mode) {
+    case 0:
+      hour++;
+      if (hour>23) hour=0;
+      break;
+    case 1:
+      minute++;
+      if (minute>59) minute=0;
+      break;
+    case 2:
+      second++;
+      if (second>59) second=0;
+      break;
+    case 3:
+      year++;
+      break;
+    case 4:
+      month++;
+      if (month>12) month=1;
+      break;
+    case 5:
+      monthDay++;
+      if (monthDay>31) monthDay=1;
+      break;
+    }
+  }
+  else if (qe1Move=='<') {
+    switch (date_mode) {
+    case 0:
+      hour--;
+      if (hour<0) hour=23;
+      break;
+    case 1:
+      minute--;
+      if (minute<0) minute=59;
+      break;
+    case 2:
+      second--;
+      if (second<0) second=59;
+      break;
+    case 3:
+      year--;
+      if (year<0) year=2012;
+      break;
+    case 4:
+      month--;
+      if (month<1) month=12;
+      break;
+    case 5:
+      monthDay--;
+      if (monthDay<1) monthDay=31;
+      break;
+    }
+  }
+
+}
+// *********************************************************************************************
+//            Darbs ar BAR zimesanu un dimmesanu
+// *********************************************************************************************
+
+void printBARs(){
+
+  if (DIMM_value[cha_incr+0]!=DIMM_temp[cha_incr+0]){
+    lcd.setCursor(0, 1);
+    lcd.write(4);
+    BarS(DIMM_value[cha_incr+0],1,1);
+    DIMM_temp[cha_incr+0]=DIMM_value[cha_incr+0];
+    analogWrite(DIMM_pin[cha_incr+0], DIMM_value[cha_incr+0]);
+  }
+
+
+  if (DIMM_value[cha_incr+1]!=DIMM_temp[cha_incr+1]){
+    lcd.setCursor(0, 2);
+    lcd.write(5);
+    BarS(DIMM_value[cha_incr+1],1,2);
+    DIMM_temp[cha_incr+1]=DIMM_value[cha_incr+1];
+    analogWrite(DIMM_pin[cha_incr+1], DIMM_value[cha_incr+1]);
+  }
+
+  if(DIMM_value[cha_incr+2]!=DIMM_temp[cha_incr+2]) {
+    lcd.setCursor(8, 1);
+    lcd.write(6);
+    BarS(DIMM_value[cha_incr+2],9,1);
+    DIMM_temp[cha_incr+2]=DIMM_value[cha_incr+2];
+    analogWrite(DIMM_pin[cha_incr+2], DIMM_value[cha_incr+2]);
+  }
+
+  if (DIMM_value[cha_incr+3]!=DIMM_temp[cha_incr+3]){
+    lcd.setCursor(8, 2);
+    lcd.write(7);
+    BarS(DIMM_value[cha_incr+3],9,2);
+    DIMM_temp[cha_incr+3]=DIMM_value[cha_incr+3];
+    analogWrite(DIMM_pin[cha_incr+3], DIMM_value[cha_incr+3]);
+  }
+}
+
+// *********************************************************************************************
+//            Zimejam LIELO BAR
+// *********************************************************************************************
+void BarL(int a) {// a cik
+  int a_interpolating=a/8.5;
+  int b=1;
+  int c=1;
+  a_interpolating=a_interpolating+1;
+  int d;
+  d=a_interpolating/2;
+  d=d-1;
+
+
+  for (int i=0; i<= d-1; i++){
+    lcd.setCursor(b+i, c);
+    lcd.write(null);
+  }
+  if (b+d!=b-1) {
+    lcd.setCursor(b+d, c);
+    if ( (a_interpolating % 2) == 0) {
+      lcd.write(1);
+    }
+    else {
+      lcd.write(null);
+    } //2
+  }
+
+  if (b+d+1!=b+15) { // 7 cik zimigas pozicijas aiznjem BAR
+    lcd.setCursor(b+d+1, c);
+    lcd.write(" ");
+  }
+
+/*
+  lcd.setCursor(0, 2);
+  if (DIMM_increment==1) {
+    lcd.write(char_small_step);
+  }
+  else {
+    lcd.write(char_big_step);
+  }
+  lcd.print(a);
+  lcd.print(" ");
+*/
+  /*   vecais temperaturas attelosanai
+   int tmpa=int(temp[DIMM_active]);
+   lcd.setCursor(6, 2);
+   lcd.print(tmpa);
+   lcd.write(223);
+   */
+
+
+  if (menu_mode!=3) {
+    lcd.setCursor(10, 2);
+    lcd.print("      ");
+    lcd.setCursor(10, 2);
+    lcd.print(a/5.6);
+    lcd.print("W");
+  }
+}
+
+
+
+// *********************************************************************************************
+
+void BarS(int a, int b, int c) {// a cik
+  int a_interpolating=a/18.2;
+  a_interpolating=a_interpolating+1;
+  int d;
+  d=a_interpolating/2;
+  d=d-1;
+  for (int i=0; i<= d-1; i++){
+    lcd.setCursor(b+i, c);
+    lcd.write(null);
+  }
+  if (b+d!=b-1) {
+    lcd.setCursor(b+d, c);
+    if ( (a_interpolating % 2) == 0) {
+      lcd.write(1);
+    }
+    else {
+      lcd.write(null);
+    } //2
+  }
+
+  if (b+d+1!=b+7) { // 7 cik zimigas pozicijas aiznjem BAR
+    lcd.setCursor(b+d+1, c);
+    lcd.write(" ");
+  }
+}
+
+
+// *********************************************************************************************
+//            Darbs ar BAR pirmatneja ekrana iestadisana
+// *********************************************************************************************
+void DimmingStart(){
+  cha=0;
+
+  lcd.setCursor(0, 0);
+  lcd.print(menu_text[menu_mode-1]);
+
+  lcd.setCursor(5, 0);
+  lcd.write(":");
+  lcd.write(DIMM_text[cha_incr+cha]);
+
+  lcd.setCursor(12, 0);
+  lcd.write(char_big_step);
+
+  DIMM_increment=DIMM_increment_S;
+
+  DIMM_temp[cha_incr+0]=-1;
+  DIMM_temp[cha_incr+1]=-1;
+  DIMM_temp[cha_incr+2]=-1;
+  DIMM_temp[cha_incr+3]=-1;
+  printBARs();
+}
+
+// *********************************************************************************************
+//            Darbs ar BAR pirmatneja BIG bar ekrana iestadisana
+// *********************************************************************************************
+void DimmingBIGStart(){
+  lcd.setCursor(0, 0);
+  lcd.print(menu_text[menu_mode-1]);
+
+  lcd.setCursor(0, 2);
+  lcd.write(char_big_step);
+
+  DIMM_increment=DIMM_increment_B;
+
+  for (int i=0; i<= 8; i++){ // clear tmporary data, 8 Moon chanel
+    DIMM_temp[i]=-1;
+  }
+  // print local menu position
+  if (menu_mode!=3) {
+    lcd.setCursor(14, 0);
+    lcd.write(3);
+    lcd.print(".");
+  }
+
+}
+
+
+
+// *********************************************************************************************
+//            Darbs ar mazo BAR
+// *********************************************************************************************
+void Dimming(){
+
+  if (Button=='a') {   // ENCODER BUTTON
+    lcd.setCursor(dimmP[cha], dimmL[cha]);
+    lcd.write(cha+4);
+    // rakstam krasas nosaukumu
+    lcd.setCursor(6, 0);
+    lcd.write("     ");
+    lcd.setCursor(6, 0);
+    lcd.write(DIMM_text[cha_incr+cha+1]);
+
+    SaveEEPROM(cha_incr+cha);
+
+    cha++;
+    if (cha>=4) {
+      menu_old=-1;
+      menu_mode=0;
+
+      Set1();
+      SetBar();
+      SetMenu();
+      lcd.clear();
+      ShowMenu();
+    }
+  }
+
+  if (Button=='3') { // fine tuning on/off
+    lcd.setCursor(12, 0);
+    if (DIMM_increment==1) {
+      DIMM_increment=DIMM_increment_S;
+      lcd.write(char_big_step);
+    }
+    else {
+      DIMM_increment=1;
+      lcd.write(char_small_step);
+    }
+  }
+
+
+
+  if (qe1Move=='>') {
+    DIMM_value[cha_incr+cha]=DIMM_value[cha_incr+cha]+DIMM_increment;
+    if (DIMM_value[cha_incr+cha]>255) {
+      DIMM_value[cha_incr+cha]=255;
+    }
+  }
+  else if (qe1Move=='<') {
+    DIMM_value[cha_incr+cha]=DIMM_value[cha_incr+cha]-DIMM_increment;
+    if (DIMM_value[cha_incr+cha]<0) {
+      DIMM_value[cha_incr+cha]=0;
+    }
+
+  }
+
+  if (cha<4) {
+    printBARs();
+    lcd.setCursor(13, 0);
+    lcd.print(toTriple(DIMM_value[cha_incr+cha]));
+
+
+    flash_pos=dimmP[cha];
+    flash_line=dimmL[cha];
+    flash_txt=String(cha+4);
+    flash=1;
+  }
+
+
+  // end void
+}
+
+
+// *********************************************************************************************
+//            Darbs ar LIEL0 BAR
+// *********************************************************************************************
+
+void Dimming_big(){
+
+  if (Button=='a') {   // ENCODER BUTTON
+    timer_mode++;
+    if (menu_mode==3) { // it kaa prueksh moon light ieprieks atslegsana
+    //Serial.println(cha);
+     timer_mode=6;
+    } else {
+
+      if (timer_mode>0) {
+        flash_pos=timer_pos[timer_mode-1];
+        flash_line=timer_line[timer_mode-1];
+
+     // atkartoti simejam laikus lai atjaunotu flash rezimaa neuzssiimeetus numurus
+            lcd.setCursor(0, 1);
+            lcd.print("Day: ");
+            lcd.print(toDouble(on_h[cha]));
+            lcd.print(":");
+            lcd.print(toDouble(on_m[cha]));
+            lcd.print("-");
+            lcd.print(toDouble(off_h[cha]));
+            lcd.print(":");
+            lcd.print(toDouble(off_m[cha]));
+
+      }
+    }
+
+
+
+    switch (timer_mode) {
+        case 1:
+          CLS();
+
+          // zimejam tekosha ekrana poziciju
+          lcd.setCursor(14, 0);
+          lcd.print(".");
+          lcd.write(3);
+
+          lcd.setCursor(0, 1);
+          lcd.print("Day: ");
+          lcd.print(toDouble(on_h[cha]));
+          lcd.print(":");
+          lcd.print(toDouble(on_m[cha]));
+          lcd.print("-");
+          lcd.print(toDouble(off_h[cha]));
+          lcd.print(":");
+          lcd.print(toDouble(off_m[cha]));
+          lcd.setCursor(0, 2);
+          lcd.print("Sunset: ");
+          lcd.print(toDouble(sunset[cha]));
+          lcd.print(" min.");
+
+          flash_txt=toDouble(on_h[cha]);
+          flash=1;
+          break;
+       case 2:
+          flash_txt=toDouble(on_m[cha]);
+          flash=1;
+          break;
+       case 3:
+          flash_txt=toDouble(off_h[cha]);
+          flash=1;
+          break;
+       case 4:
+          flash_txt=toDouble(off_m[cha]);
+          flash=1;
+          break;
+       case 5:
+          flash_txt=toDouble(sunset[cha]);
+          flash=1;
+          break;
+    }
+
+    if (timer_mode>=6) {
+      SaveEEPROM(cha);
+      menu_old=-1;
+      menu_mode=0;
+      lcd.clear();
+      SetMenu();
+      ShowMenu();
+    }
+  }
+
+    if (timer_mode==0) { // set LED level with bar
+      if (Button=='3') { // fine tunning on/off
+        lcd.setCursor(0, 2);
+        if (DIMM_increment==1) {
+          DIMM_increment=DIMM_increment_B;
+          lcd.write(char_big_step);
+        }
+        else {
+          DIMM_increment=1;
+          lcd.write(char_small_step);
+        }
+      }
+    }
+    if (qe1Move=='>') {
+      switch (timer_mode) {
+        case 0:
+          DIMM_value[cha]=DIMM_value[cha]+DIMM_increment;
+          if (DIMM_value[cha]>255) {
+            DIMM_value[cha]=255;
+          }
+          break;
+        case 1:
+          on_h[cha]++;
+          if (on_h[cha]>23) on_h[cha]=0;
+          flash_txt=toDouble(on_h[cha]);
+          break;
+        case 2:
+          on_m[cha]++;
+          if (on_m[cha]>59) on_m[cha]=0;
+          flash_txt=toDouble(on_m[cha]);
+          break;
+        case 3:
+          off_h[cha]++;
+          if (off_h[cha]>23) off_h[cha]=0;
+          flash_txt=toDouble(off_h[cha]);
+          break;
+        case 4:
+          off_m[cha]++;
+          if (off_m[cha]>59) off_m[cha]=0;
+          flash_txt=toDouble(off_m[cha]);
+          break;
+        case 5:
+          sunset[cha]=sunset[cha]+1;
+          if (sunset[cha]>60) sunset[cha]=1;
+          flash_txt=toDouble(sunset[cha]);
+          break;
+      }
+    }
+    else if (qe1Move=='<') {
+      switch (timer_mode) {
+        case 0:
+          DIMM_value[cha]=DIMM_value[cha]-DIMM_increment;
+          if (DIMM_value[cha]<0) {
+            DIMM_value[cha]=0;
+          }
+          break;
+        case 1:
+          on_h[cha]--;
+          if (on_h[cha]<0) on_h[cha]=23;
+          flash_txt=toDouble(on_h[cha]);
+          break;
+        case 2:
+          on_m[cha]--;
+          if (on_m[cha]<0) on_m[cha]=59;
+           flash_txt=toDouble(on_m[cha]);
+          break;
+        case 3:
+          off_h[cha]--;
+          if (off_h[cha]<0) off_h[cha]=23;
+          flash_txt=toDouble(off_h[cha]);
+          break;
+        case 4:
+          off_m[cha]--;
+          if (off_m[cha]<0) off_m[cha]=59;
+          flash_txt=toDouble(off_m[cha]);
+          break;
+        case 5:
+          sunset[cha]=sunset[cha]-5;
+          if (sunset[cha]<0) sunset[cha]=60;
+           flash_txt=toDouble(sunset[cha]);
+          break;
+      }
+    }
+
+    if (timer_mode==0) {
+      if (DIMM_value[cha]!=DIMM_temp[cha]){
+        BarL(DIMM_value[cha]);
+        DIMM_temp[cha]=DIMM_value[cha];
+        analogWrite(DIMM_pin[cha], DIMM_value[cha]);
+      }
+      lcd.setCursor(1, 2);
+      lcd.print(toTriple(DIMM_value[cha]));
+     // flash_pos=dimmP[0];
+     // flash_line=dimmL[0];
+
+      flash_pos=0;
+      flash_line=1;
+      flash_txt=" "; //String(cha+4);
+      flash=1;
+    }
+
+  // end void
+}
+
+
+// *********************************************************************************************
+//            Taimeru darbibas
+// *********************************************************************************************
+
+void Watch(){
+  long on_sec;
+  long off_sec;
+  long now_sec;
+  long tmp_sunset;
+
+// fot internal
+  long DIMM_long;
+
+  float tmp;
+
+  //int out;
+  int actual_led;
+  int now_mode=0; // 0 - normal, 1 sun Up, 2 sun Down
+
+
+  hour2 = RTC.get(DS1307_HR,true);
+  minute2 = RTC.get(DS1307_MIN,false);
+  second2 = RTC.get(DS1307_SEC,false);
+
+
+  now_sec=((long(hour2)*3600)+(long(minute2)*60))+long(second2);
+
+  // for all defined timer
+  for (int i=0; i<=7; i++){
+    // init for calcultion
+    on_sec=(long(on_h[i])*3600)+(long(on_m[i])*60);
+    off_sec=(long(off_h[i])*3600)+(long(off_m[i])*60);
+    tmp_sunset=long(sunset[i])*60;
+    DIMM_long=long(DIMM_value[i]);
+
+
+// normal situation - time_on < to time_off
+      if (on_sec<off_sec) {
+
+// light on
+          if (now_sec>=on_sec && now_sec<=off_sec){
+            DIMM_actual[i]=(int) DIMM_long;
+            now_mode=0;
+
+// normals sunset +
+            if (now_sec<=(on_sec+tmp_sunset)){
+                tmp=(((float)DIMM_long/(float)tmp_sunset)*(float)((on_sec+tmp_sunset)-now_sec));
+                DIMM_long = DIMM_long -tmp;
+                DIMM_actual[i]=(int) DIMM_long;
+                now_mode=1;
+            }
+
+ // normals sundown -
+            if (now_sec>=off_sec-tmp_sunset){
+                tmp=((float)DIMM_long/(float)tmp_sunset)*(float)((off_sec-tmp_sunset)-now_sec);
+                tmp=abs(tmp);
+      	        DIMM_long = DIMM_long -(long)tmp;
+                DIMM_actual[i]=(int) DIMM_long;
+                now_mode=2;
+            }
+
+// light off
+          } else {
+            DIMM_actual[i]=0;
+            now_mode=0;
+          }
+      }
+
+//**********************************************************************************************
+// extra situation - time_on > to time_off
+      if (on_sec>off_sec) {
+
+// light off
+         if (now_sec>=off_sec && now_sec<on_sec){
+	    DIMM_actual[i]=0;
+            now_mode=0;
+
+// light on
+         } else {
+  	    DIMM_actual[i]=(int) DIMM_long;
+
+// normals sunrise
+            if (now_sec<on_sec+tmp_sunset && now_sec>off_sec){
+                 tmp=(((float)DIMM_long/(float)tmp_sunset)*(float)((on_sec+tmp_sunset)-now_sec));
+      	         DIMM_long = DIMM_long -(long) tmp;
+                 DIMM_actual[i]=(int) DIMM_long;
+                 now_mode=2;
+              }
+
+// sunsets, kas turpinas pec pusnakts (iesledz 23.55, izsledz 02.00, sunrise 20)
+	      if ((on_sec+tmp_sunset)>86400 && (now_sec-on_sec)<0 && now_sec<(tmp_sunset-(86400-on_sec))){
+                  tmp=(((float)DIMM_long/(float)tmp_sunset)*(float)(((on_sec+tmp_sunset)-86400)-now_sec));
+      	          DIMM_long = DIMM_long -(long) tmp;
+                  DIMM_actual[i]=(int) DIMM_long;
+                  now_mode=1;
+              }
+
+// normals sunset
+	      if (now_sec>=off_sec-tmp_sunset && now_sec<off_sec){
+                  tmp=((float)DIMM_long/(float)tmp_sunset)*(float)((off_sec-tmp_sunset)-now_sec);
+                  tmp=abs(tmp);
+      	          DIMM_long = DIMM_long -(long) tmp;
+                  DIMM_actual[i]=(int) DIMM_long;
+                  now_mode=1;
+              }
+
+// sundowns, kas jasak rekinat pirms pusnakts (iesledz 20.00 , izsledz 00.10 un sunrise 15)
+  	      if ((tmp_sunset-off_sec)>0 && (86400-now_sec)<=(tmp_sunset-off_sec)){
+                  tmp=((float)DIMM_long/(float)tmp_sunset)*(float)(((off_sec-tmp_sunset)-now_sec)+86400);
+                  tmp=abs(tmp);
+      	          DIMM_long = DIMM_long -(long)tmp;
+                  DIMM_actual[i]=(int) DIMM_long;
+                  now_mode=2;
+              }
+        }
+      }
+
+      if (manual_on==2) { analogWrite(DIMM_pin[i], DIMM_actual[i]); }
+      if (manual_on==0) { analogWrite(DIMM_pin[i], 0); }
+      if (manual_on==1) { analogWrite(DIMM_pin[i], DIMM_value[i]); }
+
+
+
+      if (menu_mode==-2) {
+        //if (manual_on==2) { actual_led=DIMM_actual[i]; }
+        //if (manual_on==0) { actual_led=0; }
+        //if (manual_on==1) { actual_led=DIMM_value[i]; }
+
+        lcd.setCursor(LED_pos[i], LED_line[i]);
+        lcd.print(toTriple(DIMM_actual[i]));
+
+        lcd.setCursor(LED_pos[i]-1, LED_line[i]);
+        if (now_mode==0) {
+          lcd.print(" ");
+        }
+        if (now_mode==1) {
+          lcd.print("+");
+        }
+        if (now_mode==2) {
+          lcd.print("-");
+        }
+      }
+
+
+  } // for
+
+}
+
+
+// *********************************************************************************************
+//            Temperatura
+// *********************************************************************************************
+void Termo() {
+
+if (millis() > (temp_time+1000)) {
+  byte i;
+  byte present = 0;
+  byte type_s;
+  byte data[12];
+  byte addr[8];
+  float celsius, fahrenheit;
+
+  if ( !ds.search(addr)) {
+    temp_counter=0;
+    ds.reset_search();
+    return;
+  }
+
+  ds.reset();
+  ds.select(addr);
+  ds.write(0x44, 1);        // start conversion, with parasite power on at the end
+
+
+  present = ds.reset();
+  ds.select(addr);
+  ds.write(0xBE);         // Read Scratchpad
+  for ( i = 0; i < 9; i++) {           // we need 9 bytes
+    data[i] = ds.read();
+  }
+  int16_t raw = (data[1] << 8) | data[0];
+  if (type_s) {
+    raw = raw << 3; // 9 bit resolution default
+    if (data[7] == 0x10) {
+      // "count remain" gives full 12 bit resolution
+      raw = (raw & 0xFFF0) + 12 - data[6];
+    }
+  } else {
+    byte cfg = (data[4] & 0x60);
+    // at lower res, the low bits are undefined, so let's zero them
+    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
+    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
+    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
+    //// default is 12 bit resolution, 750 ms conversion time
+  }
+  celsius = (float)raw / 16.0;
+  temp[temp_counter]=celsius;
+  temp_counter++;
+  temp_time=millis();
+
+  // contriol Temp
+ if (temp[0]>=fan_on) {
+   digitalWrite(pinFan, HIGH);
+   FAN_status=1;
+ }
+ if (temp[0]<=fan_off) {
+   digitalWrite(pinFan, LOW);
+   FAN_status=0;
+ }
+
+
+}
+
+
+}
+
+
+// *********************************************************************************************
+//            Voltage
+// *********************************************************************************************
+
+void Voltage(){
+  // read the value on analog input
+  //for ( int i = 0; i < 2; i++) {
+    /*
+    volt_sensor_value = analogRead(volt_sensot_PIN[0]);
+    vout = (volt_sensor_value * 5.0) / 1024.0;
+    vin = vout / (R2/(R1+R2));
+    volt[0]=(volt[0]+vin)/2;
+    */
+    //volt[0]=volt_sensor_value;
+ // }
+ /*
+  Serial.print("Vin=");
+  Serial.print(vin);
+  Serial.print("V");
+
+  Serial.print("  V=");
+  Serial.print(volt[0]);
+  Serial.print("V");
+
+
+  Serial.print("  value=");
+  Serial.print(volt_sensor_value);
+
+
+  Serial.println();
+ */
+
+}
+
+
+// *********************************************************************************************
+//            Print status on screenSaver mode
+// *********************************************************************************************
+
+void PrintStatus(){
+// te vajag displeja Modi skat'ties un tad druk't
+
+  if (menu_mode==-2) { // tipa screensavers
+      int hr = hour2;
+      int mn = minute2;
+      int sc = second2;
+
+ //   flash_timer++;
+ //   if (flash_timer<=1) {
+      lcd.setCursor(0, 0);
+      lcd.print(toDouble(hr));
+      lcd.print(":");
+      lcd.print(toDouble(mn));
+      lcd.print(":");
+      lcd.print(toDouble(sc));
+ //   }
+ //  if (flash_timer==2) {
+ //     flash_timer=0;
+ //    lcd.setCursor(0, 0);
+ //     lcd.print(toDouble(hr));
+ //     lcd.print(" ");
+ //     lcd.print(toDouble(mn ));
+ //   }
+
+  }
+
+   if (temperature_mode==0) {
+     int tmpa=int(temp[0]);
+     lcd.setCursor(12, 0);
+     lcd.print(tmpa);
+     lcd.write(223);
+     lcd.print("C");
+     lcd.setCursor(10, 0);
+     if (FAN_status==1) {
+        lcd.write(42);
+     } else {
+        lcd.write(238);
+     }
+
+manual_modes_show();
+
+
+
+   }
+
+   if (temperature_mode==1) {
+     int tmpa=int(temp[0]);
+     lcd.setCursor(10, 2);
+     lcd.print(temp[0]);
+     lcd.write(223);
+
+   }
+}
+
+void ScreenSaver(){ //zerro
+
+  currentSens1 = analogRead(A1_pin);
+  // convert to milli amps
+  CurrentValue1 = (((long)currentSens1 * 5000 / 1024) - 500 ) * 1000 / 100;
+  amps1 = (float) CurrentValue1 / 1000;
+ // lcd.setCursor(8, 1);
+
+ // lcd.print(amps1);
+ // lcd.print("mA");
+  //lcd.print(currentSens1);
+  float watts = (amps1 * volt[0])/100;
+  //lcd.setCursor(8, 2);
+
+ // lcd.print(watts);
+ // lcd.print("W");
+
+}
+
+void manual_modes_show(){
+       if (manual_on==2) {
+        lcd.setCursor(9, 0);
+        lcd.print("A");
+      }
+      if (manual_on==0) {
+        lcd.setCursor(9, 0);
+        //lcd.write(245);
+       lcd.print("_");
+      }
+      if (manual_on==1) {
+        lcd.setCursor(9, 0);
+        lcd.write(255);
+      }
+}


Add actual motor code

Add actual motor code

error: pathspec 'MotorTest/MotorTest.ino' did not match any file(s) known to git

--- MotorTest/MotorTest.ino
+++ MotorTest/MotorTest.ino
@@ -0,0 +1,125 @@
+/*-----( Import needed libraries )-----*/
+#include <Stepper.h>
+
+/*-----( Declare Constants, Pin Numbers )-----*/
+//---( Number of steps per revolution of INTERNAL motor in 4-step mode )---
+#define STEPS_PER_MOTOR_REVOLUTION 32
+
+//---( Steps per OUTPUT SHAFT of gear reduction )---
+#define STEPS_PER_OUTPUT_REVOLUTION 128  // 5
+
+#define lightPin 0
+#define laserPin 7
+#define motorDelay 3
+#define laserDelay 5
+#define threshold 70
+#define motorSpeed 700
+
+int note9 = 0x61;
+int note8 = 0x63;
+int note7 = 0x64;
+int note6 = 0x66;
+int note5 = 0x68;
+int note4 = 0x70;
+int note3 = 0x71;
+int note2 = 0x40;
+int note1 = 0x47;
+
+Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);
+
+int  Steps2Take;
+int current;
+int stepID;
+int light;
+
+void setup()   /*----( SETUP: RUNS ONCE )----*/
+{
+// Nothing  (Stepper Library sets pins as outputs)
+  Serial.begin(115200);
+  pinMode(laserPin, OUTPUT);
+}/*--(end setup )---*/
+
+void parsePosition() {
+  switch (stepID) {
+    case 1:
+      noteOn(0x90, note1, 0x7F);
+      break;
+    case 2:
+      noteOn(0x90, note2, 0x7F);
+      break;
+    case 3:
+      noteOn(0x90, note3, 0x7F);
+      break;
+    case 4:
+      noteOn(0x90, note4, 0x7F);
+      break;
+    case 5:
+      noteOn(0x90, note5, 0x7F);
+      break;
+    case 6:
+      noteOn(0x90, note6, 0x7F);
+      break;
+    case 7:
+      noteOn(0x90, note7, 0x7F);
+      break;
+    case 8:
+      noteOn(0x90, note8, 0x7F);
+      break;
+    default:
+      noteOn(0x90, note1, 0x00);
+      break;
+  }
+}
+
+void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
+{
+  for (int i = 1; i <= 8; i++) {
+    digitalWrite(laserPin, LOW);
+    small_stepper.setSpeed(motorSpeed);
+    small_stepper.step(16);
+    stepID = i;
+    delay(motorDelay);
+    digitalWrite(laserPin, HIGH);
+    delay(laserDelay);
+    light = analogRead(lightPin);
+    if (light > threshold) {
+      parsePosition();
+    } else {
+      noteOn(0x90, 0x1E, 0x00);
+    }
+//    Serial.print("ID: ");
+//    Serial.print(stepID);
+//    Serial.print(" Value: ");
+//    Serial.println(light);
+  }
+  // delay(1000);
+  for (int i = 8; i >= 1; i--) {
+    digitalWrite(laserPin, LOW);
+    small_stepper.setSpeed(motorSpeed);
+    small_stepper.step(-16);
+    stepID = i;
+    delay(motorDelay);
+    digitalWrite(laserPin, HIGH);
+    delay(laserDelay);
+    light = analogRead(lightPin);
+    if (light > threshold) {
+      parsePosition();
+    } else {
+      noteOn(0x90, 0x1E, 0x00);
+    }
+//    Serial.print("ID: ");
+//    Serial.print(stepID);
+//    Serial.print(" Value: ");
+//    Serial.println(light);
+  }
+  // delay(2000);
+
+}/* --(end main loop )-- */
+
+void noteOn(int cmd, int pitch, int velocity) {
+  Serial.write(cmd);
+  Serial.write(pitch);
+  Serial.write(velocity);
+}
+
+/* ( THE END ) */


skp 09

skp 09

error: pathspec 'starter_kit_project_09/starter_kit_project_09.ino' did not match any file(s) known to git

--- starter_kit_project_09/starter_kit_project_09.ino
+++ starter_kit_project_09/starter_kit_project_09.ino
@@ -0,0 +1,23 @@
+const int switchPin = 2;
+const int motorPin = 9;
+
+void setup() {
+
+  pinMode(motorPin, OUTPUT);
+  pinMode(switchPin, INPUT);
+
+}
+
+void loop() {
+
+  if (digitalRead(switchPin) == HIGH) {
+
+    digitalWrite(motorPin, HIGH);
+
+  } else {
+
+    digitalWrite(motorPin, LOW);
+
+  }
+
+}


* added "other axis lockout" so joystick only moves on direction at a time (x or y) instead of diagonal (x and y) * fixed invalid setting "JoysticksGetValues" should be "DebugJoysticksGetValues"

error: pathspec 'Wheel' did not match any file(s) known to git
error: pathspec 'Button' did not match any file(s) known to git
error: pathspec 'Box/arduino_pro-micro_button_box/arduino_pro-micro_button_box.ino' did not match any file(s) known to git


another sensor test file to commit

another sensor test file to commit

Commmit the digital version for the optical limit switch sketch.

error: pathspec 'Sensor' did not match any file(s) known to git
error: pathspec 'Tests/Individual_Sensor_Sketches/Optical' did not match any file(s) known to git
error: pathspec 'limit' did not match any file(s) known to git
error: pathspec 'switch/optical_limit_switch_preliminary_test/optical_limit_switch_preliminary_digital_test.ino.ino' did not match any file(s) known to git


Add Ultrasonic Sensor

Add Ultrasonic Sensor

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/merktassel/research-project-2015.git/'


registrando o voto

registrando o voto

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/ciandt-dev/garage-kelvin-celsius.git/'


Created Network version of code

Created Network version of code

error: pathspec 'Arduino_HVAC_Controller/Networked_HVAC_Controller/Networked_HVAC_Controller.ino' did not match any file(s) known to git

--- Arduino_HVAC_Controller/Networked_HVAC_Controller/Networked_HVAC_Controller.ino
+++ Arduino_HVAC_Controller/Networked_HVAC_Controller/Networked_HVAC_Controller.ino
@@ -0,0 +1,278 @@
+// name:     Networked_HVAC_Controller.ino
+// author:   Chad Hobbs
+// created:  130121
+// last edit: 130121
+//
+// description: This program controls multiple temperature sensors via the 1-wire protocol, and turns off and on an HVAC system based on
+// presets. It communicates with a server to provide data and remote access/control.
+// Surface mount 1 address: 103EB683000800F1
+// Short lead address: 10 18 40 44 0 8 0 70
+// Long lead address: 10 CE A6 82 2 8 0 3F
+
+
+
+// -------------LIBRARIES---------------- THESE ARE REQUIRED TO BE IN YOUR SKETCHBOOK\LIBRARY FOLDER FOR COMPILING ----
+#include <OneWire.h>              // Protocol to communicate with onewire bus devices
+#include <DallasTemperature.h>    // Temperature sensor protocol
+#include <Wire.h>                 // Protocol to communicate with I2C devices
+#include <Adafruit_MCP23017.h>    // LCD protocol
+#include <Adafruit_RGBLCDShield.h>// LCD + Button shield protocol
+
+// --------------PARAMETERS---------------------
+byte addrs[1][8] = {{16,206,166,130,2,8,0,63}};  // THIS IS PARTICULAR TO THE SPECIFIC DS1820 USED
+                                  // {16,24,64,68,0,8,0,112} Temp Sensor 1
+                                  // {16,206,166,130,2,8,0,63} Temp Sensor 2 unused at this time
+int busPin = 4;                   // Data bus for One Wire Comms
+int numOfDevices = 1;             // How many sensors are in loop
+int heat = 70;                    // This is the default heater trigger temp setting
+int cool = 80;                    // This is the default cooling trigger temp setting
+int buffer = 2;                   // This is the range away from the setpoint the heat or AC will overcool/heat to prevent shorter cycles
+int heatPin = 7;                  // Digital pin used for turning on the heater relay
+int coolPin = 8;                  // Digital pin used for turning on the AC relay
+int cycleTime - 600000;           // The length of time to delay running the AC or heat to prevent short boolean
+cycling heatRunning = FALSE;      // Stores whether the heater is currently running or not
+boolean coolRunning = FALSE;      // Stores whether the AC is currently running or not
+long currentTemp = 0.0;           // Current room temperature
+int serialSpeed = 9600;           // Default serial comm speed
+long oldTemp = 0;                 // Used to only update the currentTemp if the temp has changed
+unsigned long timeOut;            // Backlight timeout variable
+boolean editable = FALSE;         // Determines whether or not button presses will do anything, used to avoid accidental changes
+char* menu[] = {"Cooling", "Heating"};  // Menu display for either setting the high point or the low point of the temp range
+int menuPosition = 1;             // Current position in the setting menu
+unsigned long heatLastRan;        // Stores the time the heater last ran
+unsigned long coolLastRan;        // Stores the time the AC last ran
+
+// -------------Library Interaction--------------
+// Data wire is plugged into busPin on the Arduino
+#define ONE_WIRE_BUS busPin
+
+// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
+OneWire oneWire(ONE_WIRE_BUS);
+
+// Pass our oneWire reference to Dallas Temperature.
+DallasTemperature sensors(&oneWire);
+//void wdt_reset(void);
+
+// arrays to hold device address
+DeviceAddress insideThermometer = { 0x10, 0x39, 0xe2, 0x82, 0x02, 0x08, 0x00, 0x3e }; // THIS IS PARTICULAR TO THE SPECIFIC DS1820 USED
+
+// Create our LCD Shield instance
+Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
+#define ON 0x7            // For single color LCD, set on to white
+#define OFF 0x0           // For single color LCD, set off to black
+
+// ----------------------------------------------------------------------------------------
+// Function Name: setup()
+// Parameters:    None
+// Returns:       None
+// Description:   This function executes housekeeping duties and staging for the loop() function; executed once
+// ----------------------------------------------------------------------------------------
+void setup(){
+
+  pinMode(busPin,INPUT);  // Designate temperature bus pin data direction
+  pinMode(heatPin,OUTPUT);                // Heat circuit relay
+  pinMode(coolPin,OUTPUT);                // Cooling circuit relay
+  Serial.begin(serialSpeed);
+
+  sensors.begin();        // Start up the library. IC Default is 9 bit. If you have troubles consider upping it 12. Ups the delay
+  lcd.begin(16, 2);       // set up the LCD's number of columns and rows
+  lcd.setBacklight(ON);   // Start off with backlight on until time-out
+  timeOut = millis();     // Set the initial backlight time
+
+}
+
+// ----------------------------------------------------------------------------------------
+// Function Name: loop()
+// Parameters:    None
+// Returns:       None
+// Description:   This is the main executing block of the program, calling all ancillary functions to operate the Arduino
+// ----------------------------------------------------------------------------------------
+void loop(){
+  if ((millis() - timeOut) > 30000) {                   // Turn on backlight for 30 seconds, else turn it off
+    lcd.setBacklight(OFF);
+    editable == FALSE;
+  }else {
+    lcd.setBacklight(ON);
+  }
+
+  lcd.setCursor(0, 1);                  // Starting postion of character printing
+
+  uint8_t buttons = lcd.readButtons();  // Constantly check to see if something has been put on the bus
+
+  // --------------Handle updating Temp Change Display---------------------
+  if (getTemp()) {                      // Constantly check to see if the temperature has changed, and update appropriately
+    lcd.clear();
+    lcd.print("Current Temp: ");
+    lcd.print(currentTemp);
+  }
+
+  // --------------Handle Button Presses---------------------
+  if (buttons) {
+    timeOut = millis();
+    lcd.setBacklight(ON);
+
+
+    if (buttons & BUTTON_SELECT) {      // Allow parameters to be changed only if the Select button has been pressed first
+      editable = TRUE;
+    }
+    if (editable) {                     // go to buttonHandler to handle menu switching and parameter manipulations
+      buttonHandler(buttons);
+    }
+  }
+
+  // --------------Handle Heat and Cooling Cycles---------------------
+  powerControl();
+
+}
+
+// ----------------------------------------------------------------------------------------
+// Function Name: powerControlHandler()
+// Parameters:    None
+// Returns:       None
+// Description:   This function will handle turning AC or Heat off and on based on current temp, timers, and setpoints
+// ----------------------------------------------------------------------------------------
+void powerControl(){
+
+  // TODO: Add in fan relay control
+
+
+  // This executes if the heater is running and it gets warm enough to turn off.
+  if (heatRunning && (currentTemp > (heat + buffer))) {
+      heatRunning = FALSE;
+      heatLastRan = millis();
+      digitalWrite(heatPin,HIGH);
+      return;
+    }
+  }
+
+  // This executes if the AC is running and it gets cool enough to turn off
+  if (coolRunning && (currentTemp < (cool - buffer))) {
+      coolRunning = FALSE;
+      coolLastRan = millis();
+      digitalWrite(coolPin,HIGH);
+      return;
+    }
+  }
+
+  // This executes if it gets cold enough and the heater has not run for a minimum time (short cycle protection)
+  if ((currentTemp < heat) && ((millis() - heatLastRan) > cycleTime) {
+    digitalWrite(heatPin,HIGH);
+    heatRunning = TRUE;
+    return;
+  }
+
+  // This executes if it gets hot enough and the AC has not run for 10 minutes (short cycle protection)
+  if ((currentTemp > cool) && ((millis() - coolLastRan) > 600000) {
+    digitalWrite(coolPin,HIGH);
+    coolRunning = TRUE;
+    return;
+  }
+
+  return;
+}
+
+
+// ----------------------------------------------------------------------------------------
+// Function Name: buttonHandler()
+// Parameters:    None
+// Returns:       Boolean, True if the temperature has changed, else False
+// Description:   This function polls the temp sensors, retrieves the values, and then returns
+// ----------------------------------------------------------------------------------------
+boolean buttonHandler(uint8_t buttons){
+
+  // --------------PARAMETERS---------------------
+  int heatModifier = 0;
+  int coolModifier = 0;
+
+
+  // --------------SETUP---------------------
+  lcd.clear();
+
+  // If the UP Button is pushed, increasing the setpoint
+  if (buttons & BUTTON_UP) {
+    if (menuPosition == 0) {
+      coolModifier = 1;
+    }
+    if (menuPosition == 1) {
+      heatModifier = 1;
+    }
+  }
+
+  // If the Down Button is pushed, decreasing the setpoint
+  if (buttons & BUTTON_DOWN) {
+    if (menuPosition == 0) {
+      coolModifier = -1;
+    }
+    if (menuPosition == 1) {
+      heatModifier = -1;
+    }
+  }
+
+  // If the Left Button is pushed, change the menu context
+  if (buttons & BUTTON_LEFT) {
+    if (menuPosition == 1){
+      menuPosition = 0;
+    }else {
+      menuPosition = 1;
+    }
+  }
+
+  // If the Right Button is pushed, change the menu context
+  if (buttons & BUTTON_RIGHT) {
+    if (menuPosition == 1){
+      menuPosition = 0;
+    }else {
+      menuPosition = 1;
+    }
+  }
+
+  // If anything has been modified, update accordingly
+  heat = heat + heatModifier;
+  cool = cool + coolModifier;
+
+  // Print proper menu title and setpoint
+  lcd.setCursor(0, 0);
+  lcd.print(menu[menuPosition]);
+  lcd.setCursor(0, 1);
+  lcd.print("Setpoint: ");
+
+  if (menuPosition == 0) {
+    lcd.print(cool);
+  }
+  if (menuPosition == 1) {
+    lcd.print(heat);
+  }
+
+}
+
+// ----------------------------------------------------------------------------------------
+// Function Name: getTemp()
+// Parameters:    None
+// Returns:       Boolean, True if the temperature has changed, else False
+// Description:   This function polls the temp sensors, retrieves the values, and then returns
+// ----------------------------------------------------------------------------------------
+boolean getTemp(){
+  currentTemp = 0;
+  long temp = 0;
+  sensors.requestTemperatures(); // Send the command to the device to get temperatures
+
+  // Go through devices and read the temperatures
+  for(int x = 0; x < numOfDevices; x++){
+    temp = sensors.getTempF(addrs[x]);
+    if(temp != currentTemp){
+      currentTemp = temp;
+    }
+  }
+
+  // Check to see if temperature has changed
+  if (currentTemp != oldTemp) {
+    oldTemp = currentTemp;
+    return true;
+  }
+  else {
+    return false;
+  }
+}
+
+
+


code1

code1

you can control a laser and a light on your watch by this code!

1.hit the button to light the display
2.hold the button until the display shows 1
3.hit to add until you get the number you want(1.laser,2.light,3,setTime,4.coming soon)
4.hit again to leave

error: pathspec 'code1.ino' did not match any file(s) known to git

--- code1.ino
+++ code1.ino
@@ -0,0 +1,627 @@
+/*
+ * Richardn
+ * the repository on github
+ * Sparkfun-BigTime-Watch-Kit-Extension-Code
+ * read readme.md first
+ * to use this code,first you should solder a light on A3 and a laser on A4
+ *
+ *
+ * 1.hit the button to light the display
+ * 2.hold the button until the display shows 1
+ * 3.hit to add until you get the number you want(1.laser,2.light,3,setTime,4.coming soon)
+ * 4.hit again to leave
+ *
+ */
+
+/*
+ 7-17-2011
+ Spark Fun Electronics 2011
+ Nathan Seidle
+ */
+#include "main.h"
+
+#include <avr/sleep.h> //Needed for sleep_mode
+#include <avr/power.h> //Needed for powering down perihperals such as the ADC/TWI and Timers
+
+//Declaring this will enable IR broadcast when you hit the time button twice
+//By default, we don't enable this
+//#define ENABLE_TVBGONE
+
+//Set the 12hourMode to false for military/world time. Set it to true for American 12 hour time.
+int TwelveHourMode = false;//richardn:i think 15:00 is better than 3:00
+
+//Set this variable to change how long the time is shown on the watch face. In milliseconds so 1677 = 1.677 seconds
+int show_time_length = 1000;//richardn:i shorten it to 1 sec
+int show_the_time = false;
+
+//You can set always_on to true and the display will stay on all the time
+//This will drain the battery in about 15 hours
+int always_on = false;
+
+long seconds = 55;
+int minutes = 12;
+int hours = 8;
+
+int display_brightness = 15000; //A larger number makes the display more dim. This is set correctly below.
+
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//Pin definitions
+int digit1 = 9; //Display pin 1
+int digit2 = 10; //Display pin 2
+int digit3 = A0; //Display pin 6
+int digit4 = A1; //Display pin 8
+
+int segA = 6; //Display pin 14
+int segB = 8; //Display pin 16
+int segC = 5; //Display pin 13
+int segD = 11; //Display pin 3
+int segE = 13; //Display pin 5
+int segF = 4; //Display pin 11
+int segG = 7; //Display pin 15
+
+int colons = 12; //Display pin 4
+int ampm = 3; //Display pin 10
+
+int theButton = 2;
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+//The very important 32.686kHz interrupt handler
+SIGNAL(TIMER2_OVF_vect){
+  seconds += 8; //We sleep for 8 seconds instead of 1 to save more power
+  //seconds++; //Use this if we are waking up every second
+
+  //Update the minutes and hours variables
+  minutes += seconds / 60; //Example: seconds = 2317, minutes = 58 + 38 = 96
+  seconds %= 60; //seconds = 37
+  hours += minutes / 60; //12 + (96 / 60) = 13
+  minutes %= 60; //minutes = 36
+
+  //Do we display 12 hour or 24 hour time?
+  if(TwelveHourMode == true) {
+    //In 12 hour mode, hours go from 12 to 1 to 12.
+    while(hours > 12) hours -= 12;
+  }
+  else {
+    //In 24 hour mode, hours go from 0 to 23 to 0.
+    while(hours > 23) hours -= 24;
+  }
+}
+
+//The interrupt occurs when you push the button
+SIGNAL(INT0_vect){
+  //When you hit the button, we will need to display the time
+  //if(show_the_time == false)
+  show_the_time = true;
+}
+
+void setup() {
+
+  //To reduce power, setup all pins as inputs with no pullups
+  for(int x = 1 ; x < 18 ; x++){
+    pinMode(x, INPUT);
+    digitalWrite(x, LOW);
+  }
+
+  pinMode(A4,OUTPUT);//richardn:the laser pin
+  pinMode(A3,OUTPUT);//richardn:the light pin
+
+  pinMode(theButton, INPUT); //This is the main button, tied to INT0
+  digitalWrite(theButton, HIGH); //Enable internal pull up on button
+
+  //These pins are used to control the display
+  pinMode(segA, OUTPUT);
+  pinMode(segB, OUTPUT);
+  pinMode(segC, OUTPUT);
+  pinMode(segD, OUTPUT);
+  pinMode(segE, OUTPUT);
+  pinMode(segF, OUTPUT);
+  pinMode(segG, OUTPUT);
+
+  pinMode(digit1, OUTPUT);
+  pinMode(digit2, OUTPUT);
+  pinMode(digit3, OUTPUT);
+  pinMode(digit4, OUTPUT);
+  pinMode(colons, OUTPUT);
+  pinMode(ampm, OUTPUT);
+
+  //Power down various bits of hardware to lower power usage
+  set_sleep_mode(SLEEP_MODE_PWR_SAVE);
+  sleep_enable();
+
+  //Shut off ADC, TWI, SPI, Timer0, Timer1
+
+  ADCSRA &= ~(1<<ADEN); //Disable ADC
+  ACSR = (1<<ACD); //Disable the analog comparator
+  DIDR0 = 0x3F; //Disable digital input buffers on all ADC0-ADC5 pins
+  DIDR1 = (1<<AIN1D)|(1<<AIN0D); //Disable digital input buffer on AIN1/0
+
+  power_twi_disable();
+  power_spi_disable();
+  //  power_usart0_disable(); //Needed for serial.print
+  //power_timer0_disable(); //Needed for delay and millis()
+  power_timer1_disable();
+  //power_timer2_disable(); //Needed for asynchronous 32kHz operation
+
+  //Setup TIMER2
+  TCCR2A = 0x00;
+  //TCCR2B = (1<<CS22)|(1<<CS20); //Set CLK/128 or overflow interrupt every 1s
+  TCCR2B = (1<<CS22)|(1<<CS21)|(1<<CS20); //Set CLK/1024 or overflow interrupt every 8s
+  ASSR = (1<<AS2); //Enable asynchronous operation
+  TIMSK2 = (1<<TOIE2); //Enable the timer 2 interrupt
+
+  //Setup external INT0 interrupt
+  EICRA = (1<<ISC01); //Interrupt on falling edge
+  EIMSK = (1<<INT0); //Enable INT0 interrupt
+
+  //System clock futzing
+  //CLKPR = (1<<CLKPCE); //Enable clock writing
+  //CLKPR = (1<<CLKPS3); //Divid the system clock by 256
+
+  showTime(); //Show the current time for a few seconds
+
+  sei(); //Enable global interrupts
+}
+
+void loop() {
+  if(always_on == false)
+    sleep_mode(); //Stop everything and go to sleep. Wake up if the Timer2 buffer overflows or if you hit the button
+
+  if(show_the_time == true || always_on == true) {
+
+    //Debounce
+    while(digitalRead(theButton) == LOW) ; //Wait for you to remove your finger
+    delay(100);
+    while(digitalRead(theButton) == LOW) ; //Wait for you to remove your finger
+
+    /*Serial.print(hours, DEC);
+     Serial.print(":");
+     Serial.print(minutes, DEC);
+     Serial.print(":");
+     Serial.println(seconds, DEC);*/
+
+    showTime(); //Show the current time for a few seconds//richardn:showing the time will let you know that the battery is correctly placed
+
+    //If you are STILL holding the button, then you must want to adjust the time
+    if(digitalRead(theButton) == LOW) functions();//richardn:defined below
+
+    show_the_time = false; //Reset the button variable
+  }
+}
+
+//richardn:all my code
+void functions(){
+  int startTime1 = millis();
+  int chosenNumber = 1;
+  while(millis()-startTime1<2000){
+    if(digitalRead(theButton) == LOW){
+      while(digitalRead(theButton) == LOW){
+      }
+      if(chosenNumber < 4){
+        chosenNumber++;
+      }else{
+        chosenNumber - 3;
+      }
+    }
+    lightNumber(chosenNumber);
+  }
+  switch(chosenNumber){
+    case 1 :
+    function1();
+    break;
+    case 2 :
+    function2();
+    break;
+    case 3 :
+    setTime();
+    break;
+    case 4 :
+    break;
+  }
+}
+
+void function1(){
+  while(digitalRead(theButton) == HIGH){
+    digitalWrite(A4,HIGH);
+  }
+}
+
+void function2(){
+  while(digitalRead(theButton) == HIGH){
+    digitalWrite(A3,HIGH);
+  }
+}
+//richardn:my code finished
+
+void showTime() {
+
+  //Here is where we display the time and PWM the segments
+  //Display brightness changes based on color, red is too bright, blue is very dull
+  //By painting the time, then turning off for a number of microseconds, we can control how bright the display is
+
+  //Each digit is on for a certain amount of microseconds
+  //Then it is turned off and we go to the next digit
+  //We loop through each digit until we reach the show_time_length (usually about 2 seconds)
+
+  //For the default red display:
+  //Let's define a variable called display_brightness that varies from:
+  //5000 blindingly bright (15.7mA current draw per digit)
+  //2000 shockingly bright (11.4mA current draw per digit)
+  //1000 pretty bright (5.9mA)
+  //500 normal (3mA)
+  //200 dim but readable (1.4mA)
+  //50 dim but readable (0.56mA)
+  //5 dim but readable (0.31mA)
+  //1 dim but readable in dark (0.28mA)
+
+  int combinedTime = (hours * 100) + minutes; //Combine the hours and minutes
+  //int combinedTime = (minutes * 100) + seconds; //For testing, combine the minutes and seconds
+
+  boolean buttonPreviouslyHit = false;
+
+  //Now show the time for a certain length of time
+  long startTime = millis();
+  while( (millis() - startTime) < show_time_length) {
+    displayNumber(combinedTime, true); //Each call takes about 8ms, display the colon
+
+    //After the time is displayed, the segments are turned off
+    //We control the brightness by modifying how long we wait between re-paints of the display
+    //delayMicroseconds(display_brightness);
+
+    //If you have hit and released the button while the display is on, start the IR off sequence
+    if(digitalRead(theButton) == LOW) {
+      buttonPreviouslyHit = true;
+    }
+    else if( (buttonPreviouslyHit == true) && (digitalRead(theButton) == HIGH) ) {
+
+#ifdef ENABLE_TVBGONE
+      //Disable TIMER2 for IR control
+      TCCR2A = 0x00;
+      TCCR2B = 0;
+      ASSR = 0;
+      TIMSK2 = 0; //Enable the timer 2 interrupt
+
+      //Turn off all the things!
+      sendAllCodes();
+
+      //Setup TIMER2
+      TCCR2A = 0x00;
+      //TCCR2B = (1<<CS22)|(1<<CS20); //Set CLK/128 or overflow interrupt every 1s
+      TCCR2B = (1<<CS22)|(1<<CS21)|(1<<CS20); //Set CLK/1024 or overflow interrupt every 8s
+      ASSR = (1<<AS2); //Enable asynchronous operation
+      TIMSK2 = (1<<TOIE2); //Enable the timer 2 interrupt
+
+      quickflashLEDx(2); //Blink Colons twice letting us know it's done
+#endif
+
+      return;
+    }
+  }
+
+}
+
+//Displays a string on the display
+//Used to indicate which code is loaded onto the watch
+void showColor(char *colorName) {
+
+  //Now show the letters for a certain length of time
+  long startTime = millis();
+  while( (millis() - startTime) < show_time_length) {
+    displayLetters(colorName); //Each call takes about 8ms, display the colon
+
+    //After the letters are displayed, the segments are turned off
+    //We control the brightness by modifying how long we wait between re-paints of the display
+    delayMicroseconds(display_brightness);
+  }
+}
+
+//This routine occurs when you hold the button down
+//The colon blinks indicating we are in this mode
+//Holding the button down will increase the time (accelerates)
+//Releasing the button for more than 2 seconds will exit this mode
+void setTime(void) {
+
+  int idleMiliseconds = 0;
+  //This is the timeout counter. Once we get to ~2 seconds of inactivity, the watch
+  //will exit the setTime function and return to normal operation
+
+  int buttonHold = 0;
+  //This counts the number of times you are holding the button down consecutively
+  //Once we notice you're really holding the button down a lot, we will speed up the minute counter
+
+  while(idleMiliseconds < 2000) {
+
+    cli(); //We don't want the interrupt changing values at the same time we are!
+
+    //Update the minutes and hours variables
+    minutes += seconds / 60; //Example: seconds = 2317, minutes = 58 + 38 = 96
+    seconds %= 60; //seconds = 37
+    hours += minutes / 60; //12 + (96 / 60) = 13
+    minutes %= 60; //minutes = 36
+
+    //Do we display 12 hour or 24 hour time?
+    if(TwelveHourMode == true) {
+      //In 12 hour mode, hours go from 12 to 1 to 12.
+      while(hours > 12) hours -= 12;
+    }
+    else {
+      //In 24 hour mode, hours go from 0 to 23 to 0.
+      while(hours > 23) hours -= 24;
+    }
+
+    sei(); //Resume interrupts
+
+    int combinedTime = (hours * 100) + minutes; //Combine the hours and minutes
+
+      for(int x = 0 ; x < 10 ; x++) {
+      displayNumber(combinedTime, true); //Each call takes about 8ms, display the colon for about 100ms
+      delayMicroseconds(display_brightness); //Wait before we paint the display again
+    }
+    for(int x = 0 ; x < 10 ; x++) {
+      displayNumber(combinedTime, false); //Each call takes about 8ms, turn off the colon for about 100ms
+      delayMicroseconds(display_brightness); //Wait before we paint the display again
+    }
+
+    //If you're still hitting the button, then increase the time and reset the idleMili timeout variable
+    if(digitalRead(theButton) == LOW) {
+      idleMiliseconds = 0;
+
+      buttonHold++;
+      if(buttonHold < 10) //10 = 2 seconds
+        minutes++; //Advance the minutes
+      else {
+        //Advance the minutes faster because you're holding the button for 10 seconds
+        //Start advancing on the tens digit. Floor the single minute digit.
+        minutes /= 10; //minutes = 46 / 10 = 4
+        minutes *= 10; //minutes = 4 * 10 = 40
+        minutes += 10;  //minutes = 40 + 10 = 50
+      }
+    }
+    else
+      buttonHold = 0;
+
+    idleMiliseconds += 200;
+  }
+}
+
+//This is a not-so-accurate delay routine
+//Calling fake_msdelay(100) will delay for about 100ms
+//Assumes 8MHz clock
+/*void fake_msdelay(int x){
+ for( ; x > 0 ; x--)
+ fake_usdelay(1000);
+ }*/
+
+//This is a not-so-accurate delay routine
+//Calling fake_usdelay(100) will delay for about 100us
+//Assumes 8MHz clock
+/*void fake_usdelay(int x){
+ for( ; x > 0 ; x--) {
+ __asm__("nop\n\t");
+ __asm__("nop\n\t");
+ __asm__("nop\n\t");
+ __asm__("nop\n\t");
+ __asm__("nop\n\t");
+ __asm__("nop\n\t");
+ __asm__("nop\n\t");
+ }
+ }*/
+
+//Given 1022, we display "10:22"
+//Each digit is displayed for ~2000us, and cycles through the 4 digits
+//After running through the 4 numbers, the display is turned off
+void displayNumber(int toDisplay, boolean displayColon) {
+
+#define DIGIT_ON  HIGH
+#define DIGIT_OFF  LOW
+
+  for(int digit = 4 ; digit > 0 ; digit--) {
+
+    //Turn on a digit for a short amount of time
+    switch(digit) {
+    case 1:
+      digitalWrite(digit1, DIGIT_ON);
+      break;
+    case 2:
+      digitalWrite(digit2, DIGIT_ON);
+      if(displayColon == true) digitalWrite(colons, DIGIT_ON); //When we update digit 2, let's turn on colons as well
+      break;
+    case 3:
+      digitalWrite(digit3, DIGIT_ON);
+      break;
+    case 4:
+      digitalWrite(digit4, DIGIT_ON);
+      break;
+    }
+
+    //Now display this digit
+    if(digit > 1)
+      lightNumber(toDisplay % 10); //Turn on the right segments for this digit
+    else if(digit == 1) { //Special case on first digit, don't display 02:11, display 2:11
+      if( (toDisplay % 10) != 0) //If we are on the first digit, and it's not zero
+        lightNumber(toDisplay % 10); //Turn on the right segments for this digit
+    }
+
+    toDisplay /= 10;
+
+    delayMicroseconds(2000); //Display this digit for a fraction of a second (between 1us and 5000us, 500-2000 is pretty good)
+    //If you set this too long, the display will start to flicker. Set it to 25000 for some fun.
+
+    //Turn off all segments
+    lightNumber(10);
+
+    //Turn off all digits
+    digitalWrite(digit1, DIGIT_OFF);
+    digitalWrite(digit2, DIGIT_OFF);
+    digitalWrite(digit3, DIGIT_OFF);
+    digitalWrite(digit4, DIGIT_OFF);
+    digitalWrite(colons, DIGIT_OFF);
+    digitalWrite(ampm, DIGIT_OFF);
+  }
+
+}
+
+//Takes a string like "gren" and displays it, left justified
+//We don't use the colons, or AMPM dot, so they are turned off
+void displayLetters(char *colorName) {
+#define DIGIT_ON  HIGH
+#define DIGIT_OFF  LOW
+
+  digitalWrite(digit4, DIGIT_OFF);
+  digitalWrite(colons, DIGIT_OFF);
+  digitalWrite(ampm, DIGIT_OFF);
+
+  for(int digit = 0 ; digit < 4 ; digit++) {
+    //Turn on a digit for a short amount of time
+    switch(digit) {
+    case 0:
+      digitalWrite(digit1, DIGIT_ON);
+      break;
+    case 1:
+      digitalWrite(digit2, DIGIT_ON);
+      break;
+    case 2:
+      digitalWrite(digit3, DIGIT_ON);
+      break;
+    case 3:
+      digitalWrite(digit4, DIGIT_ON);
+      break;
+    }
+
+    //Now display this letter
+    lightNumber(colorName[digit]); //Turn on the right segments for this letter
+
+    delayMicroseconds(2000); //Display this digit for a fraction of a second (between 1us and 5000us, 500-2000 is pretty good)
+    //If you set this too long, the display will start to flicker. Set it to 25000 for some fun.
+
+    //Turn off all segments
+    lightNumber(10);
+
+    //Turn off all digits
+    digitalWrite(digit1, DIGIT_OFF);
+    digitalWrite(digit2, DIGIT_OFF);
+    digitalWrite(digit3, DIGIT_OFF);
+  }
+}
+
+//Given a number, turns on those segments
+//If number == 10, then turn off all segments
+void lightNumber(int numberToDisplay) {
+
+#define SEGMENT_ON  LOW
+#define SEGMENT_OFF HIGH
+
+  /*
+Segments
+   -  A
+   F / / B
+   -  G
+   E / / C
+   -  D
+   */
+
+  switch (numberToDisplay){
+
+  case 0:
+    digitalWrite(segA, SEGMENT_ON);
+    digitalWrite(segB, SEGMENT_ON);
+    digitalWrite(segC, SEGMENT_ON);
+    digitalWrite(segD, SEGMENT_ON);
+    digitalWrite(segE, SEGMENT_ON);
+    digitalWrite(segF, SEGMENT_ON);
+    break;
+
+  case 1:
+    digitalWrite(segB, SEGMENT_ON);
+    digitalWrite(segC, SEGMENT_ON);
+    break;
+
+  case 2:
+    digitalWrite(segA, SEGMENT_ON);
+    digitalWrite(segB, SEGMENT_ON);
+    digitalWrite(segD, SEGMENT_ON);
+    digitalWrite(segE, SEGMENT_ON);
+    digitalWrite(segG, SEGMENT_ON);
+    break;
+
+  case 3:
+    digitalWrite(segA, SEGMENT_ON);
+    digitalWrite(segB, SEGMENT_ON);
+    digitalWrite(segC, SEGMENT_ON);
+    digitalWrite(segD, SEGMENT_ON);
+    digitalWrite(segG, SEGMENT_ON);
+    break;
+
+  case 4:
+    digitalWrite(segB, SEGMENT_ON);
+    digitalWrite(segC, SEGMENT_ON);
+    digitalWrite(segF, SEGMENT_ON);
+    digitalWrite(segG, SEGMENT_ON);
+    break;
+
+  case 5:
+    digitalWrite(segA, SEGMENT_ON);
+    digitalWrite(segC, SEGMENT_ON);
+    digitalWrite(segD, SEGMENT_ON);
+    digitalWrite(segF, SEGMENT_ON);
+    digitalWrite(segG, SEGMENT_ON);
+    break;
+
+  case 6:
+    digitalWrite(segA, SEGMENT_ON);
+    digitalWrite(segC, SEGMENT_ON);
+    digitalWrite(segD, SEGMENT_ON);
+    digitalWrite(segE, SEGMENT_ON);
+    digitalWrite(segF, SEGMENT_ON);
+    digitalWrite(segG, SEGMENT_ON);
+    break;
+
+  case 7:
+    digitalWrite(segA, SEGMENT_ON);
+    digitalWrite(segB, SEGMENT_ON);
+    digitalWrite(segC, SEGMENT_ON);
+    break;
+
+  case 8:
+    digitalWrite(segA, SEGMENT_ON);
+    digitalWrite(segB, SEGMENT_ON);
+    digitalWrite(segC, SEGMENT_ON);
+    digitalWrite(segD, SEGMENT_ON);
+    digitalWrite(segE, SEGMENT_ON);
+    digitalWrite(segF, SEGMENT_ON);
+    digitalWrite(segG, SEGMENT_ON);
+    break;
+
+  case 9:
+    digitalWrite(segA, SEGMENT_ON);
+    digitalWrite(segB, SEGMENT_ON);
+    digitalWrite(segC, SEGMENT_ON);
+    digitalWrite(segD, SEGMENT_ON);
+    digitalWrite(segF, SEGMENT_ON);
+    digitalWrite(segG, SEGMENT_ON);
+    break;
+
+  case 10:
+    digitalWrite(segA, SEGMENT_OFF);
+    digitalWrite(segB, SEGMENT_OFF);
+    digitalWrite(segC, SEGMENT_OFF);
+    digitalWrite(segD, SEGMENT_OFF);
+    digitalWrite(segE, SEGMENT_OFF);
+    digitalWrite(segF, SEGMENT_OFF);
+    digitalWrite(segG, SEGMENT_OFF);
+    break;
+
+    /*
+Segments
+     -  A
+     F / / B
+     -    G
+     E / / C
+     - D
+     */
+  }
+}
+
+
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+


Create ver2.ino

Create ver2.ino

error: pathspec 'Dalal/Robot/ver2.ino' did not match any file(s) known to git

--- Dalal/Robot/ver2.ino
+++ Dalal/Robot/ver2.ino
@@ -0,0 +1,165 @@
+#include <SoftwareSerial.h>
+#include <Motor.h>
+#include <NewPing.h>
+
+#define buzzer 2
+#define trig 8
+#define echo 7
+#define max_dist 100
+
+NewPing frontSonar(trig, echo, max_dist);
+
+int speed = 100;
+
+bool button_control = false;
+bool desktop = false;
+
+motorpins pins = {6, 9, 3, 5};
+
+Motor motor(pins);
+
+int led = 13;
+
+SoftwareSerial bt(10, 11); //rx tx
+
+float values = -100;
+float yValues = -100;
+
+int x_value = 0;
+int y_value = 0;
+
+int direction = 0;
+
+void setup() {
+  // put your setup code here, to run once:
+  Serial.begin(9600);
+  bt.begin(9600);
+  pinMode(led, OUTPUT);
+  pinMode(buzzer, OUTPUT);
+}
+
+int getX(String value){
+  String x = value.substring(1, value.indexOf(','));
+  return x.toInt();
+}
+
+int getY(String value){
+  String y = value.substring(value.indexOf(',') + 1, value.indexOf(')'));
+  return y.toInt();
+}
+
+String incomingByte = "";
+
+void loop() {
+  // put your main code here, to run repeatedly:
+  if (bt.available() > 0){
+    //values = bt.parseFloat();
+    //yValues = bt.parseFloat();
+
+    //Serial.println("x values: " + String(values) + "\n y values: " + String(yValues));
+    String compositeData = bt.readStringUntil('\n');
+    incomingByte = compositeData;
+
+    Serial.println(incomingByte);
+    Serial.println(incomingByte.equals("W"));
+
+    if (compositeData.startsWith("~")) {
+      button_control = true;
+      desktop = false;
+      if (compositeData.equals("~FORWARD")) {Serial.println("fwd"); direction = 9000;}
+      else if (compositeData.equals("~BACKWARD")) {Serial.println("back"); direction = 10000;}
+      else if (compositeData.equals("~LEFT")) {Serial.println("left"); direction = 11000;}
+      else if (compositeData.equals("~RIGHT")) {Serial.println("right") ; direction = 12000;}
+      else if (compositeData.equals("~STOP")) {Serial.println("stop"); direction = 13000;}
+
+
+    }
+
+
+    else if (compositeData.startsWith("W") ||
+        compositeData.startsWith("S") ||
+        compositeData.startsWith("A") ||
+        compositeData.startsWith("D") ||
+        compositeData.startsWith("q")){
+          Serial.println("data got");
+          desktop = true;
+        }
+
+
+
+    else {
+      button_control = false;
+      desktop = false;
+      x_value = getX(compositeData);
+      y_value = getY(compositeData);
+    }
+
+//    Serial.println("x: " +  String(x_value));
+//    Serial.println(x);
+
+    delay(10);
+  }
+
+  if (button_control == false){
+
+
+  if (x_value > -8 && x_value < -3){
+
+
+    Serial.println("FORWARD");
+    motor.go(speed, speed, FORWARD);
+  }
+
+    else if (x_value > 3 && x_value < 8){
+     Serial.println("BACKWARD");
+    motor.go(speed, speed, BACKWARD);
+  }
+
+    else if (y_value > 3 && y_value < 8){
+    Serial.println("LEFT");
+    motor.go(0, speed, LEFT);
+  }
+
+
+  else if (y_value > -8 && y_value < -3){
+
+
+    Serial.println("RIGHT");
+    motor.go(speed, 0, RIGHT);
+  }
+
+  else {
+    motor.go(0, 0, NOWHERE);
+  }
+
+  } else {
+
+    if (direction == 9000){
+      motor.go(speed, speed, FORWARD);
+    } else if (direction == 10000){
+      motor.go(speed, speed, BACKWARD);
+    } else if (direction == 11000){
+
+      motor.go(speed, speed, RIGHT);
+    } else if (direction == 12000){
+      motor.go(speed, speed, LEFT);
+    } else if (direction == 13000){
+      motor.go(0, 0, NOWHERE);
+    }
+  }
+
+
+  if (desktop == true){
+    if (incomingByte.equals("W")) { motor.go(speed, speed, FORWARD); Serial.println("forward");}
+    else if (incomingByte.equals("S")) { motor.go(speed, speed, BACKWARD); Serial.println("backward"); }
+    else if (incomingByte.equals("A")) { motor.go(speed, speed, LEFT); Serial.println("left"); }
+    else if (incomingByte.equals("D")) {motor.go(speed, speed, RIGHT); Serial.println("right");}
+    else  motor.go(0, 0, NOWHERE);
+  }
+
+  if (frontSonar.ping_cm() > 2 && frontSonar.ping_cm() < 10){
+    digitalWrite(buzzer, HIGH);
+  } else digitalWrite(buzzer, LOW);
+
+
+}


Add gateway code

Add gateway code

error: pathspec 'gateway/Gateway.ino' did not match any file(s) known to git

--- gateway/Gateway.ino
+++ gateway/Gateway.ino
@@ -0,0 +1,285 @@
+#include <RFM69.h>    //get it here: https://www.github.com/lowpowerlab/rfm69
+#include <RFM69_ATC.h>//get it here: https://www.github.com/lowpowerlab/rfm69
+#include <SPI.h>      //comes with Arduino IDE (www.arduino.cc)
+#include <Tone.h>
+
+#include <SerialCommand.h>
+
+SerialCommand SCmd;   // The demo SerialCommand object
+
+//*********************************************************************************************
+//************ IMPORTANT SETTINGS - YOU MUST CHANGE/CONFIGURE TO FIT YOUR HARDWARE *************
+//*********************************************************************************************
+#define NODEID        254    //unique for each node on same network
+#define NETWORKID     100  //the same on all nodes that talk to each other
+//Match frequency to the hardware version of the radio on your Moteino (uncomment one):
+//#define FREQUENCY     RF69_433MHZ
+#define FREQUENCY     RF69_868MHZ
+//#define FREQUENCY     RF69_915MHZ
+#define ENCRYPTKEY    "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
+//#define IS_RFM69HW    //uncomment only for RFM69HW! Leave out if you have RFM69W!
+//#define ENABLE_ATC    //comment out this line to disable AUTO TRANSMISSION CONTROL
+//*********************************************************************************************
+
+#define SERIAL_BAUD   115200
+
+#ifdef __AVR_ATmega1284P__
+  #define LED           15 // Moteino MEGAs have LEDs on D15
+  #define FLASH_SS      23 // and FLASH SS on D23
+#else
+  #define LED           9 // Moteinos have LEDs on D9
+  #define FLASH_SS      8 // and FLASH SS on D8
+#endif
+
+#ifdef ENABLE_ATC
+  RFM69_ATC radio;
+#else
+  RFM69 radio;
+#endif
+
+bool promiscuousMode = false; //set to 'true' to sniff all packets on the same network
+
+Tone player;
+
+static union {
+	char buff[10];
+	struct {
+		uint8_t nodeId;
+		uint8_t messageId;
+		uint16_t batteryVoltage;
+		uint8_t calibration;
+		uint8_t laserTripped;
+	} s;
+} packet;
+
+char buff[1];
+#define CMD_LASER_ON 1
+#define CMD_LASER_OFF 2
+#define CMD_CALIBRATE 3
+#define CMD_GET_STATUS 4
+
+#define BUTTON_LIGHT 6
+#define BUTTON A3
+#define LEDS 5
+#define SIREN 4
+
+#define ALL 255
+
+void sendCommand(uint8_t to, uint8_t cmd) {
+  buff[0] = cmd;
+  radio.send(to, buff, 1);
+}
+
+void laserControll(uint8_t cmd) {
+  char *arg;
+  uint8_t address = ALL;
+
+  arg = SCmd.next();
+
+  if (arg != NULL) {
+    address=atoi(arg);
+  }
+
+  sendCommand(address, cmd);
+}
+
+void laserOn() {
+  laserControll(CMD_LASER_ON);
+}
+
+void laserOff() {
+  laserControll(CMD_LASER_OFF);
+}
+
+void laserStatus() {
+  laserControll(CMD_GET_STATUS);
+}
+
+void laserCalibrate() {
+  laserControll(CMD_CALIBRATE);
+}
+
+void initDetectors() {
+  sendCommand(ALL, CMD_LASER_OFF);
+  delay(1000);
+  sendCommand(ALL, CMD_CALIBRATE);
+  delay(1500);
+  sendCommand(ALL, CMD_LASER_ON);
+  delay(100);
+  sendCommand(ALL, CMD_GET_STATUS);
+}
+
+void discover() {
+  sendCommand(ALL, CMD_LASER_OFF);
+  delay(1000);
+  if(radio.receiveDone()){
+  }
+
+  for(uint8_t i = 1; i <= 20; i++) {
+    sendCommand(i, CMD_LASER_ON);
+    Serial.print(i, DEC);
+    delay(100);
+    uint32_t ts = millis();
+    uint8_t responseReceived = 0;
+    sendCommand(ALL, CMD_LASER_OFF);
+    while(millis() - ts < 50 && !responseReceived) {
+      if(radio.receiveDone()){
+        for (byte i = 0; i < radio.DATALEN; i++) {
+          packet.buff[i] = (char)radio.DATA[i];
+        }
+        responseReceived = 1;
+        Serial.print(" sviecia i ");
+        Serial.println(packet.s.nodeId, DEC);
+      }
+    }
+    if(!responseReceived) {
+      Serial.println(" niekur");
+    }
+  }
+}
+
+void setup() {
+  pinMode(BUTTON, INPUT_PULLUP);
+  pinMode(BUTTON_LIGHT, OUTPUT);
+  digitalWrite(BUTTON_LIGHT, HIGH);
+  pinMode(LEDS, OUTPUT);
+  pinMode(SIREN, OUTPUT);
+
+  Serial.begin(SERIAL_BAUD);
+  delay(10);
+
+  SCmd.addCommand("ON",laserOn);
+  SCmd.addCommand("OFF",laserOff);
+  SCmd.addCommand("init",initDetectors);
+  SCmd.addCommand("discover", discover);
+  SCmd.addCommand("status", laserStatus);
+  SCmd.addCommand("calibrate", laserCalibrate);
+
+  radio.initialize(FREQUENCY,NODEID,NETWORKID);
+#ifdef IS_RFM69HW
+  radio.setHighPower(); //only for RFM69HW!
+#endif
+  radio.encrypt(0);
+  radio.promiscuous(promiscuousMode);
+  //radio.setFrequency(919000000); //set frequency to some custom frequency
+  char buff[50];
+  sprintf(buff, "\nListening at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
+  Serial.println(buff);
+
+#ifdef ENABLE_ATC
+  Serial.println("RFM69_ATC Enabled (Auto Transmission Control)");
+#endif
+  player.begin(9);
+  player.play(4000);
+  delay(200);
+  player.stop();
+
+//  sendCommand(ALL, CMD_LASER_ON);
+//  delay(100);
+
+  initDetectors();
+}
+
+byte ackCount=0;
+uint32_t packetCount = 0;
+uint8_t mode = 1;
+
+#define GAME_TIMEOUT_MS 500000
+uint32_t gameStartTs;
+
+void switchMode() {
+  if(mode) {
+    sendCommand(ALL, CMD_LASER_ON);
+    delay(650);
+    sendCommand(128, CMD_LASER_OFF);
+    gameStartTs = millis();
+  } else {
+    sendCommand(ALL, CMD_LASER_OFF);
+    digitalWrite(SIREN, HIGH);
+    delay(50);
+    digitalWrite(SIREN, LOW);
+    delay(550);
+    digitalWrite(SIREN, HIGH);
+    delay(50);
+    digitalWrite(SIREN, LOW);
+    radio.receiveDone();
+    sendCommand(128, CMD_LASER_ON);
+  }
+}
+
+
+uint8_t isGameTimeout() {
+  return (millis() - gameStartTs) > GAME_TIMEOUT_MS;
+}
+
+
+
+void loop() {
+  SCmd.readSerial();
+  if (radio.receiveDone()){
+
+    Serial.print("#[");
+    Serial.print(++packetCount);
+    Serial.print(']');
+    Serial.print('[');Serial.print(radio.SENDERID, DEC);Serial.print("] ");
+
+    for (byte i = 0; i < radio.DATALEN; i++) {
+      packet.buff[i] = (char)radio.DATA[i];
+    }
+
+    if(mode && packet.s.laserTripped) {
+      player.play(4000);
+      digitalWrite(SIREN, HIGH);
+      delay(100);
+      digitalWrite(SIREN, LOW);
+      player.stop();
+      gameStartTs = millis();
+    }
+
+    if(128 == packet.s.nodeId) {
+      mode = !mode;
+      switchMode();
+    }
+
+    Serial.print(packet.s.nodeId);
+    Serial.print(" ");
+
+    Serial.print(packet.s.messageId);
+    Serial.print(" ");
+
+    Serial.print(packet.s.batteryVoltage);
+    Serial.print(" ");
+
+    Serial.print(packet.s.calibration);
+    Serial.print(" ");
+
+    Serial.print(packet.s.laserTripped);
+
+    Serial.print("   [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]");
+
+    Serial.println();
+  }
+
+  if(LOW == digitalRead(BUTTON)) {
+    digitalWrite(LEDS, LOW);
+    digitalWrite(SIREN, HIGH);
+    gameStartTs = millis();
+  } else {
+    digitalWrite(SIREN, LOW);
+    digitalWrite(LEDS, HIGH);
+  }
+
+  if(mode && isGameTimeout()){
+    mode = 0;
+    switchMode();
+  }
+
+}
+
+void Blink(byte PIN, int DELAY_MS)
+{
+  pinMode(PIN, OUTPUT);
+  digitalWrite(PIN,HIGH);
+  delay(DELAY_MS);
+  digitalWrite(PIN,LOW);
+}


gieger

gieger

error: pathspec 'Gieger' did not match any file(s) known to git
error: pathspec 'module/code/ProbeCubeGeiger.ino' did not match any file(s) known to git