DEV Community

jay jordan
jay jordan

Posted on • Updated on

smart watch with 3d printer function

define X_STEP_PIN 54

define X_DIR_PIN 55

define X_ENABLE_PIN 38

define X_MIN_PIN 3

define X_MAX_PIN 2

define Y_STEP_PIN 60

define Y_DIR_PIN 61

define Y_ENABLE_PIN 56

define Y_MIN_PIN 14

define Y_MAX_PIN 15

define Z_STEP_PIN 46

define Z_DIR_PIN 48

define Z_ENABLE_PIN 62

define Z_MIN_PIN 18

define Z_MAX_PIN 19

define E_STEP_PIN 26

define E_DIR_PIN 28

define E_ENABLE_PIN 24

define Q_STEP_PIN 36

define Q_DIR_PIN 34

define Q_ENABLE_PIN 30

define SDPOWER -1

define SDSS 53

define LED_PIN 13

define FAN_PIN 9

define PS_ON_PIN 12

define KILL_PIN -1

define HEATER_0_PIN 10

define HEATER_1_PIN 8

define TEMP_0_PIN 13 // ANALOG NUMBERING

define TEMP_1_PIN 14 // ANALOG NUMBERING

void setup() {

pinMode(FAN_PIN , OUTPUT);

pinMode(HEATER_0_PIN , OUTPUT);

pinMode(HEATER_1_PIN , OUTPUT);

pinMode(LED_PIN , OUTPUT);

pinMode(X_STEP_PIN , OUTPUT);

pinMode(X_DIR_PIN , OUTPUT);

pinMode(X_ENABLE_PIN , OUTPUT);

pinMode(Y_STEP_PIN , OUTPUT);

pinMode(Y_DIR_PIN , OUTPUT);

pinMode(Y_ENABLE_PIN , OUTPUT);

pinMode(Z_STEP_PIN , OUTPUT);

pinMode(Z_DIR_PIN , OUTPUT);

pinMode(Z_ENABLE_PIN , OUTPUT);

pinMode(E_STEP_PIN , OUTPUT);

pinMode(E_DIR_PIN , OUTPUT);

pinMode(E_ENABLE_PIN , OUTPUT);

pinMode(Q_STEP_PIN , OUTPUT);

pinMode(Q_DIR_PIN , OUTPUT);

pinMode(Q_ENABLE_PIN , OUTPUT);

digitalWrite(X_ENABLE_PIN , LOW);

digitalWrite(Y_ENABLE_PIN , LOW);

digitalWrite(Z_ENABLE_PIN , LOW);

digitalWrite(E_ENABLE_PIN , LOW);

digitalWrite(Q_ENABLE_PIN , LOW);

}

void loop () {

if (millis() %1000 <500)

digitalWrite(LED_PIN, HIGH);

else

digitalWrite(LED_PIN, LOW);

if (millis() %1000 <300) {

digitalWrite(HEATER_0_PIN, HIGH);

digitalWrite(HEATER_1_PIN, LOW);

digitalWrite(FAN_PIN, LOW);

} else if (millis() %1000 <600) {

digitalWrite(HEATER_0_PIN, LOW);

digitalWrite(HEATER_1_PIN, HIGH);

digitalWrite(FAN_PIN, LOW);

} else {

digitalWrite(HEATER_0_PIN, LOW);

digitalWrite(HEATER_1_PIN, LOW);

digitalWrite(FAN_PIN, HIGH);

}

if (millis() %10000 <5000) {

digitalWrite(X_DIR_PIN , HIGH);

digitalWrite(Y_DIR_PIN , HIGH);

digitalWrite(Z_DIR_PIN , HIGH);

digitalWrite(E_DIR_PIN , HIGH);

digitalWrite(Q_DIR_PIN , HIGH);

}

else {

digitalWrite(X_DIR_PIN , LOW);

digitalWrite(Y_DIR_PIN , LOW);

digitalWrite(Z_DIR_PIN , LOW);

digitalWrite(E_DIR_PIN , LOW);

digitalWrite(Q_DIR_PIN , LOW);

}

digitalWrite(X_STEP_PIN , HIGH);

digitalWrite(Y_STEP_PIN , HIGH);

digitalWrite(Z_STEP_PIN , HIGH);

digitalWrite(E_STEP_PIN , HIGH);

digitalWrite(Q_STEP_PIN , HIGH);

delay(1);

digitalWrite(X_STEP_PIN , LOW);

digitalWrite(Y_STEP_PIN , LOW);

digitalWrite(Z_STEP_PIN , LOW);

digitalWrite(E_STEP_PIN , LOW);

digitalWrite(Q_STEP_PIN , LOW);

}

This code should activate all the steppers, fans, and heaters. The only problem with this code is that it does not activate both z-axis steppers; it only activates one. If you encounter any problems with any of the components, try isolating them and only running them in the code. If you would like to test the z-axis and thermistor, download the following codes:

ifndef THERMISTORTABLES_H_

define THERMISTORTABLES_H_

define OVERSAMPLENR 16

if (THERMISTORHEATER_0 == 1) || (THERMISTORHEATER_1 == 1) || (THERMISTORHEATER_2 == 1) || (THERMISTORBED == 1) //100k bed thermistor

const short temptable_1[][2] PROGMEM = {
{ 23*OVERSAMPLENR , 300 },
{ 25*OVERSAMPLENR , 295 },
{ 27*OVERSAMPLENR , 290 },
{ 28*OVERSAMPLENR , 285 },
{ 31*OVERSAMPLENR , 280 },
{ 33*OVERSAMPLENR , 275 },
{ 35*OVERSAMPLENR , 270 },
{ 38*OVERSAMPLENR , 265 },
{ 41*OVERSAMPLENR , 260 },
{ 44*OVERSAMPLENR , 255 },
{ 48*OVERSAMPLENR , 250 },
{ 52*OVERSAMPLENR , 245 },
{ 56*OVERSAMPLENR , 240 },
{ 61*OVERSAMPLENR , 235 },
{ 66*OVERSAMPLENR , 230 },
{ 71*OVERSAMPLENR , 225 },
{ 78*OVERSAMPLENR , 220 },
{ 84*OVERSAMPLENR , 215 },
{ 92*OVERSAMPLENR , 210 },
{ 100*OVERSAMPLENR , 205 },
{ 109*OVERSAMPLENR , 200 },
{ 120*OVERSAMPLENR , 195 },
{ 131*OVERSAMPLENR , 190 },
{ 143*OVERSAMPLENR , 185 },
{ 156*OVERSAMPLENR , 180 },
{ 171*OVERSAMPLENR , 175 },
{ 187*OVERSAMPLENR , 170 },
{ 205*OVERSAMPLENR , 165 },
{ 224*OVERSAMPLENR , 160 },
{ 245*OVERSAMPLENR , 155 },
{ 268*OVERSAMPLENR , 150 },
{ 293*OVERSAMPLENR , 145 },
{ 320*OVERSAMPLENR , 140 },
{ 348*OVERSAMPLENR , 135 },
{ 379*OVERSAMPLENR , 130 },
{ 411*OVERSAMPLENR , 125 },
{ 445*OVERSAMPLENR , 120 },
{ 480*OVERSAMPLENR , 115 },
{ 516*OVERSAMPLENR , 110 },
{ 553*OVERSAMPLENR , 105 },
{ 591*OVERSAMPLENR , 100 },
{ 628*OVERSAMPLENR , 95 },
{ 665*OVERSAMPLENR , 90 },
{ 702*OVERSAMPLENR , 85 },
{ 737*OVERSAMPLENR , 80 },
{ 770*OVERSAMPLENR , 75 },
{ 801*OVERSAMPLENR , 70 },
{ 830*OVERSAMPLENR , 65 },
{ 857*OVERSAMPLENR , 60 },
{ 881*OVERSAMPLENR , 55 },
{ 903*OVERSAMPLENR , 50 },
{ 922*OVERSAMPLENR , 45 },
{ 939*OVERSAMPLENR , 40 },
{ 954*OVERSAMPLENR , 35 },
{ 966*OVERSAMPLENR , 30 },
{ 977*OVERSAMPLENR , 25 },
{ 985*OVERSAMPLENR , 20 },
{ 993*OVERSAMPLENR , 15 },
{ 999*OVERSAMPLENR , 10 },
{ 1004*OVERSAMPLENR , 5 },
{ 1008*OVERSAMPLENR , 0 } //safety
};

endif

if (THERMISTORHEATER_0 == 2) || (THERMISTORHEATER_1 == 2) || (THERMISTORHEATER_2 == 2) || (THERMISTORBED == 2) //200k bed thermistor

const short temptable_2[][2] PROGMEM = {
{1*OVERSAMPLENR, 848},
{54*OVERSAMPLENR, 275},
{107*OVERSAMPLENR, 228},
{160*OVERSAMPLENR, 202},
{213*OVERSAMPLENR, 185},
{266*OVERSAMPLENR, 171},
{319*OVERSAMPLENR, 160},
{372*OVERSAMPLENR, 150},
{425*OVERSAMPLENR, 141},
{478*OVERSAMPLENR, 133},
{531*OVERSAMPLENR, 125},
{584*OVERSAMPLENR, 118},
{637*OVERSAMPLENR, 110},
{690*OVERSAMPLENR, 103},
{743*OVERSAMPLENR, 95},
{796*OVERSAMPLENR, 86},
{849*OVERSAMPLENR, 77},
{902*OVERSAMPLENR, 65},
{955*OVERSAMPLENR, 49},
{1008*OVERSAMPLENR, 17},
{1020*OVERSAMPLENR, 0} //safety
};

endif

if (THERMISTORHEATER_0 == 3) || (THERMISTORHEATER_1 == 3) || (THERMISTORHEATER_2 == 3) || (THERMISTORBED == 3) //mendel-parts

const short temptable_3[][2] PROGMEM = {
{1*OVERSAMPLENR,864},
{21*OVERSAMPLENR,300},
{25*OVERSAMPLENR,290},
{29*OVERSAMPLENR,280},
{33*OVERSAMPLENR,270},
{39*OVERSAMPLENR,260},
{46*OVERSAMPLENR,250},
{54*OVERSAMPLENR,240},
{64*OVERSAMPLENR,230},
{75*OVERSAMPLENR,220},
{90*OVERSAMPLENR,210},
{107*OVERSAMPLENR,200},
{128*OVERSAMPLENR,190},
{154*OVERSAMPLENR,180},
{184*OVERSAMPLENR,170},
{221*OVERSAMPLENR,160},
{265*OVERSAMPLENR,150},
{316*OVERSAMPLENR,140},
{375*OVERSAMPLENR,130},
{441*OVERSAMPLENR,120},
{513*OVERSAMPLENR,110},
{588*OVERSAMPLENR,100},
{734*OVERSAMPLENR,80},
{856*OVERSAMPLENR,60},
{938*OVERSAMPLENR,40},
{986*OVERSAMPLENR,20},
{1008*OVERSAMPLENR,0},
{1018*OVERSAMPLENR,-20}
};

endif

if (THERMISTORHEATER_0 == 4) || (THERMISTORHEATER_1 == 4) || (THERMISTORHEATER_2 == 4) || (THERMISTORBED == 4) //10k thermistor

const short temptable_4[][2] PROGMEM = {
{1*OVERSAMPLENR, 430},
{54*OVERSAMPLENR, 137},
{107*OVERSAMPLENR, 107},
{160*OVERSAMPLENR, 91},
{213*OVERSAMPLENR, 80},
{266*OVERSAMPLENR, 71},
{319*OVERSAMPLENR, 64},
{372*OVERSAMPLENR, 57},
{425*OVERSAMPLENR, 51},
{478*OVERSAMPLENR, 46},
{531*OVERSAMPLENR, 41},
{584*OVERSAMPLENR, 35},
{637*OVERSAMPLENR, 30},
{690*OVERSAMPLENR, 25},
{743*OVERSAMPLENR, 20},
{796*OVERSAMPLENR, 14},
{849*OVERSAMPLENR, 7},
{902*OVERSAMPLENR, 0},
{955*OVERSAMPLENR, -11},
{1008*OVERSAMPLENR, -35}
};

endif

if (THERMISTORHEATER_0 == 5) || (THERMISTORHEATER_1 == 5) || (THERMISTORHEATER_2 == 5) || (THERMISTORBED == 5) //100k ParCan thermistor (104GT-2)

const short temptable_5[][2] PROGMEM = {
{1*OVERSAMPLENR, 713},
{18*OVERSAMPLENR, 316},
{35*OVERSAMPLENR, 266},
{52*OVERSAMPLENR, 239},
{69*OVERSAMPLENR, 221},
{86*OVERSAMPLENR, 208},
{103*OVERSAMPLENR, 197},
{120*OVERSAMPLENR, 188},
{137*OVERSAMPLENR, 181},
{154*OVERSAMPLENR, 174},
{171*OVERSAMPLENR, 169},
{188*OVERSAMPLENR, 163},
{205*OVERSAMPLENR, 159},
{222*OVERSAMPLENR, 154},
{239*OVERSAMPLENR, 150},
{256*OVERSAMPLENR, 147},
{273*OVERSAMPLENR, 143},
{290*OVERSAMPLENR, 140},
{307*OVERSAMPLENR, 136},
{324*OVERSAMPLENR, 133},
{341*OVERSAMPLENR, 130},
{358*OVERSAMPLENR, 128},
{375*OVERSAMPLENR, 125},
{392*OVERSAMPLENR, 122},
{409*OVERSAMPLENR, 120},
{426*OVERSAMPLENR, 117},
{443*OVERSAMPLENR, 115},
{460*OVERSAMPLENR, 112},
{477*OVERSAMPLENR, 110},
{494*OVERSAMPLENR, 108},
{511*OVERSAMPLENR, 106},
{528*OVERSAMPLENR, 103},
{545*OVERSAMPLENR, 101},
{562*OVERSAMPLENR, 99},
{579*OVERSAMPLENR, 97},
{596*OVERSAMPLENR, 95},
{613*OVERSAMPLENR, 92},
{630*OVERSAMPLENR, 90},
{647*OVERSAMPLENR, 88},
{664*OVERSAMPLENR, 86},
{681*OVERSAMPLENR, 84},
{698*OVERSAMPLENR, 81},
{715*OVERSAMPLENR, 79},
{732*OVERSAMPLENR, 77},
{749*OVERSAMPLENR, 75},
{766*OVERSAMPLENR, 72},
{783*OVERSAMPLENR, 70},
{800*OVERSAMPLENR, 67},
{817*OVERSAMPLENR, 64},
{834*OVERSAMPLENR, 61},
{851*OVERSAMPLENR, 58},
{868*OVERSAMPLENR, 55},
{885*OVERSAMPLENR, 52},
{902*OVERSAMPLENR, 48},
{919*OVERSAMPLENR, 44},
{936*OVERSAMPLENR, 40},
{953*OVERSAMPLENR, 34},
{970*OVERSAMPLENR, 28},
{987*OVERSAMPLENR, 20},
{1004*OVERSAMPLENR, 8},
{1021*OVERSAMPLENR, 0}
};

endif

if (THERMISTORHEATER_0 == 6) || (THERMISTORHEATER_1 == 6) || (THERMISTORHEATER_2 == 6) || (THERMISTORBED == 6) // 100k Epcos thermistor

const short temptable_6[][2] PROGMEM = {
{28*OVERSAMPLENR, 250},
{31*OVERSAMPLENR, 245},
{35*OVERSAMPLENR, 240},
{39*OVERSAMPLENR, 235},
{42*OVERSAMPLENR, 230},
{44*OVERSAMPLENR, 225},
{49*OVERSAMPLENR, 220},
{53*OVERSAMPLENR, 215},
{62*OVERSAMPLENR, 210},
{73*OVERSAMPLENR, 205},
{72*OVERSAMPLENR, 200},
{94*OVERSAMPLENR, 190},
{102*OVERSAMPLENR, 185},
{116*OVERSAMPLENR, 170},
{143*OVERSAMPLENR, 160},
{183*OVERSAMPLENR, 150},
{223*OVERSAMPLENR, 140},
{270*OVERSAMPLENR, 130},
{318*OVERSAMPLENR, 120},
{383*OVERSAMPLENR, 110},
{413*OVERSAMPLENR, 105},
{439*OVERSAMPLENR, 100},
{484*OVERSAMPLENR, 95},
{513*OVERSAMPLENR, 90},
{607*OVERSAMPLENR, 80},
{664*OVERSAMPLENR, 70},
{781*OVERSAMPLENR, 60},
{810*OVERSAMPLENR, 55},
{849*OVERSAMPLENR, 50},
{914*OVERSAMPLENR, 45},
{914*OVERSAMPLENR, 40},
{935*OVERSAMPLENR, 35},
{954*OVERSAMPLENR, 30},
{970*OVERSAMPLENR, 25},
{978*OVERSAMPLENR, 22},
{1008*OVERSAMPLENR, 3}
};

endif

if (THERMISTORHEATER_0 == 7) || (THERMISTORHEATER_1 == 7) || (THERMISTORHEATER_2 == 7) || (THERMISTORBED == 7) // 100k Honeywell 135-104LAG-J01

const short temptable_7[][2] PROGMEM = {
{46*OVERSAMPLENR, 270},
{50*OVERSAMPLENR, 265},
{54*OVERSAMPLENR, 260},
{58*OVERSAMPLENR, 255},
{62*OVERSAMPLENR, 250},
{67*OVERSAMPLENR, 245},
{72*OVERSAMPLENR, 240},
{79*OVERSAMPLENR, 235},
{85*OVERSAMPLENR, 230},
{91*OVERSAMPLENR, 225},
{99*OVERSAMPLENR, 220},
{107*OVERSAMPLENR, 215},
{116*OVERSAMPLENR, 210},
{126*OVERSAMPLENR, 205},
{136*OVERSAMPLENR, 200},
{149*OVERSAMPLENR, 195},
{160*OVERSAMPLENR, 190},
{175*OVERSAMPLENR, 185},
{191*OVERSAMPLENR, 180},
{209*OVERSAMPLENR, 175},
{224*OVERSAMPLENR, 170},
{246*OVERSAMPLENR, 165},
{267*OVERSAMPLENR, 160},
{293*OVERSAMPLENR, 155},
{316*OVERSAMPLENR, 150},
{340*OVERSAMPLENR, 145},
{364*OVERSAMPLENR, 140},
{396*OVERSAMPLENR, 135},
{425*OVERSAMPLENR, 130},
{460*OVERSAMPLENR, 125},
{489*OVERSAMPLENR, 120},
{526*OVERSAMPLENR, 115},
{558*OVERSAMPLENR, 110},
{591*OVERSAMPLENR, 105},
{628*OVERSAMPLENR, 100},
{660*OVERSAMPLENR, 95},
{696*OVERSAMPLENR, 90},
{733*OVERSAMPLENR, 85},
{761*OVERSAMPLENR, 80},
{794*OVERSAMPLENR, 75},
{819*OVERSAMPLENR, 70},
{847*OVERSAMPLENR, 65},
{870*OVERSAMPLENR, 60},
{892*OVERSAMPLENR, 55},
{911*OVERSAMPLENR, 50},
{929*OVERSAMPLENR, 45},
{944*OVERSAMPLENR, 40},
{959*OVERSAMPLENR, 35},
{971*OVERSAMPLENR, 30},
{981*OVERSAMPLENR, 25},
{989*OVERSAMPLENR, 20},
{994*OVERSAMPLENR, 15},
{1001*OVERSAMPLENR, 10},
{1005*OVERSAMPLENR, 5}
};

endif

define TT_NAME(_N) temptable ## _N

define TT_NAME(_N) _TT_NAME(_N)

ifdef THERMISTORHEATER_0

#define heater_0_temptable TT_NAME(THERMISTORHEATER_0)
#define heater_0_temptable_len (sizeof(heater_0_temptable)/sizeof(*heater_0_temptable))

else

ifdef HEATER_0_USES_THERMISTOR

#error No heater 0 thermistor table specified

else // HEATER_0_USES_THERMISTOR

#define heater_0_temptable 0
#define heater_0_temptable_len 0

endif // HEATER_0_USES_THERMISTOR

endif

ifdef THERMISTORHEATER_1

#define heater_1_temptable TT_NAME(THERMISTORHEATER_1)
#define heater_1_temptable_len (sizeof(heater_1_temptable)/sizeof(*heater_1_temptable))

else

ifdef HEATER_1_USES_THERMISTOR

#error No heater 1 thermistor table specified

else // HEATER_1_USES_THERMISTOR

#define heater_1_temptable 0
#define heater_1_temptable_len 0

endif // HEATER_1_USES_THERMISTOR

endif

ifdef THERMISTORHEATER_2

#define heater_2_temptable TT_NAME(THERMISTORHEATER_2)
#define heater_2_temptable_len (sizeof(heater_2_temptable)/sizeof(*heater_2_temptable))

else

ifdef HEATER_2_USES_THERMISTOR

#error No heater 2 thermistor table specified

else // HEATER_2_USES_THERMISTOR

#define heater_2_temptable 0
#define heater_2_temptable_len 0

endif // HEATER_2_USES_THERMISTOR

endif

ifdef THERMISTORBED

#define bedtemptable TT_NAME(THERMISTORBED)
#define bedtemptable_len (sizeof(bedtemptable)/sizeof(*bedtemptable))

else

ifdef BED_USES_THERMISTOR

#error No bed thermistor table specified

endif // BED_USES_THERMISTOR

endif

endif //THERMISTORTABLES_H_

include "thermistortables.h"

define X_STEP_PIN 54

define X_DIR_PIN 55

define X_ENABLE_PIN 38

define X_MIN_PIN 3

define X_MAX_PIN 2

define Y_STEP_PIN 60

define Y_DIR_PIN 61

define Y_ENABLE_PIN 56

define Y_MIN_PIN 14

define Y_MAX_PIN 15

define Z_STEP_PIN 46

define Z_DIR_PIN 48

define Z_ENABLE_PIN 62

define Z_MIN_PIN 18

define Z_MAX_PIN 19

define E_STEP_PIN 26

define E_DIR_PIN 28

define E_ENABLE_PIN 24

define Q_STEP_PIN 36

define Q_DIR_PIN 34

define Q_ENABLE_PIN 30

define SDPOWER -1

define EXTRUDERS 3

define TEMP_SENSOR_AD595_OFFSET 0.0

define TEMP_SENSOR_AD595_GAIN 1.0

define THERMISTORHEATER_0 1

define THERMISTORHEATER_1 1

define THERMISTORHEATER_2 1

define HEATER_0_USES_THERMISTOR 1

define HEATER_1_USES_THERMISTOR 1

define HEATER_2_USES_THERMISTOR 1

static void *heater_ttbl_map[EXTRUDERS] = { (void *)heater_0_temptable

if EXTRUDERS > 1

                                       , (void *)heater_1_temptable
Enter fullscreen mode Exit fullscreen mode

endif

if EXTRUDERS > 2

                                       , (void *)heater_2_temptable
Enter fullscreen mode Exit fullscreen mode

endif

if EXTRUDERS > 3

#error Unsupported number of extruders

endif

};

static int heater_ttbllen_map[EXTRUDERS] = { heater_0_temptable_len

if EXTRUDERS > 1

                                        , heater_1_temptable_len
Enter fullscreen mode Exit fullscreen mode

endif

if EXTRUDERS > 2

                                        , heater_2_temptable_len
Enter fullscreen mode Exit fullscreen mode

endif

if EXTRUDERS > 3

#error Unsupported number of extruders

endif

};

#define PGM_RD_W(x) (short)pgm_read_word(&x)

define SDSS 53

define LED_PIN 13

define FAN_PIN 9

define PS_ON_PIN 12

define KILL_PIN -1

define HEATER_0_PIN 10

define HEATER_1_PIN 8

define TEMP_0_PIN 15 // ANALOG NUMBERING

define TEMP_1_PIN 14 // ANALOG NUMBERING

define TEMP_2_PIN 13 // ANALOG NUMBERING

void setup() {

pinMode(TEMP_0_PIN , INPUT);

pinMode(TEMP_1_PIN , INPUT);

pinMode(TEMP_2_PIN , INPUT);

pinMode(FAN_PIN , OUTPUT);

pinMode(HEATER_0_PIN , OUTPUT);

pinMode(HEATER_1_PIN , OUTPUT);

pinMode(LED_PIN , OUTPUT);

pinMode(X_STEP_PIN , OUTPUT);

pinMode(X_DIR_PIN , OUTPUT);

pinMode(X_ENABLE_PIN , OUTPUT);

pinMode(Y_STEP_PIN , OUTPUT);

pinMode(Y_DIR_PIN , OUTPUT);

pinMode(Y_ENABLE_PIN , OUTPUT);

pinMode(Z_STEP_PIN , OUTPUT);

pinMode(Z_DIR_PIN , OUTPUT);

pinMode(Z_ENABLE_PIN , OUTPUT);

pinMode(E_STEP_PIN , OUTPUT);

pinMode(E_DIR_PIN , OUTPUT);

pinMode(E_ENABLE_PIN , OUTPUT);

pinMode(Q_STEP_PIN , OUTPUT);

pinMode(Q_DIR_PIN , OUTPUT);

pinMode(Q_ENABLE_PIN , OUTPUT);

digitalWrite(X_ENABLE_PIN , LOW);

digitalWrite(Y_ENABLE_PIN , LOW);

digitalWrite(Z_ENABLE_PIN , LOW);

digitalWrite(E_ENABLE_PIN , LOW);

digitalWrite(Q_ENABLE_PIN , LOW);

Serial.begin(115200);

}

float analog2temp(int raw, uint8_t e) {

#ifdef HEATER_0_USES_MAX6675

if (e == 0)

{

 return 0.25 * raw;
Enter fullscreen mode Exit fullscreen mode

}

#endif

if(heater_ttbl_map[e] != 0)

{

float celsius = 0;

byte i;

short (tt)[][2] = (short ()[][2])(heater_ttbl_map[e]);

raw = (1023 * OVERSAMPLENR) - raw;

for (i=1; i<heater_ttbllen_map[e]; i++)

{

 if ((PGM_RD_W((*tt)[i][0]) > raw) && ((float)(PGM_RD_W((*tt)[i][0]) - PGM_RD_W((*tt)[i-1][0])) >0))

 {

   celsius = PGM_RD_W((*tt)[i-1][1]) +

     (raw - PGM_RD_W((*tt)[i-1][0])) *

     (float)(PGM_RD_W((*tt)[i][1]) - PGM_RD_W((*tt)[i-1][1])) /

     (float)(PGM_RD_W((*tt)[i][0]) - PGM_RD_W((*tt)[i-1][0]));

   break;

 }
Enter fullscreen mode Exit fullscreen mode

}

// Overflow: Set to last value in the table

if (i == heater_ttbllen_map[e]) celsius = PGM_RD_W((*tt)[i-1][1]);

return celsius;

}

return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET;

}

unsigned long prevMillis;

void loop () {

if (millis() %1000 <500)

digitalWrite(LED_PIN, HIGH);

else

digitalWrite(LED_PIN, LOW);

if (millis() %1000 <300) {

digitalWrite(HEATER_0_PIN, HIGH);

digitalWrite(HEATER_1_PIN, LOW);

digitalWrite(FAN_PIN, LOW);

} else if (millis() %1000 <600) {

digitalWrite(HEATER_0_PIN, LOW);

digitalWrite(HEATER_1_PIN, HIGH);

digitalWrite(FAN_PIN, LOW);

} else {

digitalWrite(HEATER_0_PIN, LOW);

digitalWrite(HEATER_1_PIN, LOW);

digitalWrite(FAN_PIN, HIGH);

}

if (millis() %2000 <1000) {

digitalWrite(X_DIR_PIN , HIGH);

digitalWrite(Y_DIR_PIN , HIGH);

digitalWrite(Z_DIR_PIN , HIGH);

digitalWrite(E_DIR_PIN , HIGH);

digitalWrite(Q_DIR_PIN , HIGH);

}

else {

digitalWrite(X_DIR_PIN , LOW);

digitalWrite(Y_DIR_PIN , LOW);

digitalWrite(Z_DIR_PIN , LOW);

digitalWrite(E_DIR_PIN , LOW);

digitalWrite(Q_DIR_PIN , LOW);

}

digitalWrite(X_STEP_PIN , HIGH);

digitalWrite(Y_STEP_PIN , HIGH);

digitalWrite(Z_STEP_PIN , HIGH);

digitalWrite(E_STEP_PIN , HIGH);

digitalWrite(Q_STEP_PIN , HIGH);

delay(1);

digitalWrite(X_STEP_PIN , LOW);

digitalWrite(Y_STEP_PIN , LOW);

digitalWrite(Z_STEP_PIN , LOW);

digitalWrite(E_STEP_PIN , LOW);

digitalWrite(Q_STEP_PIN , LOW);

if (millis() -prevMillis >500){

prevMillis=millis();

int t = analogRead( TEMP_0_PIN);

Serial.print("T0 ");

Serial.print(t);

Serial.print("/");

Serial.print(analog2temp(1024 - t,0),0);

Serial.print(" T1 ");

t = analogRead( TEMP_1_PIN);

Serial.print(t);

Serial.print("/");

Serial.print(analog2temp(1024 - t,1),0);

Serial.print(" T2 ");

t = analogRead( TEMP_2_PIN);

Serial.print(t);

Serial.print("/");

Serial.println(analog2temp(1024 - t,2),0);

}

}

include

include "U8glib.h"

include "SoftwareSerial.h"

include

include

define nextButton 7 //define the pin numbers for the buttons

define previousButton 5

define menuButton 4

define mot 9

define buzz A3

SoftwareSerial bluetooth(2,3); //Use software serial for bluetooth

const unsigned char PROGMEM ICON_BITMAP_1[] =
{ //Android Logo
0x00,0x00,
0x00,0x00,
0x04,0x40,
0x07,0xc0,
0x0f,0xe0,
0x0b,0xa0,
0x1f,0xf0,
0x00,0x00,
0x5f,0xf4,
0x5f,0xf4,
0x5f,0xf4,
0x5f,0xf4,
0x1f,0xf0,
0x0c,0x60,
0x0c,0x60,
0x00,0x00
};

const unsigned char PROGMEM ICON_BITMAP_20[] =
{ //chat
0x00,0x00,
0x00,0x00,
0x3f,0xf8,
0x40,0x04,
0x40,0x04,
0x40,0x04,
0x40,0x04,
0x49,0x24,
0x40,0x04,
0x40,0x04,
0x40,0x04,
0x3f,0xc8,
0x00,0x28,
0x00,0x18,
0x00,0x08,
0x00,0x00
};

const unsigned char PROGMEM ICON_BITMAP_65[] =
{ //bar signal
0x00,0x00,
0x00,0x00,
0x3f,0xe0,
0x10,0x40,
0x08,0x80,
0x05,0x00,
0x02,0x00,
0x02,0x00,
0x02,0x00,
0x00,0x0c,
0x00,0x6c,
0x03,0x6c,
0x1b,0x6c,
0x1b,0x6c,
0x00,0x00,
0x00,0x00
};

int i,c=0,t=0;

boolean clockUp = true;
boolean menuShow = false;
boolean selectButtonbool = false;
boolean newMessage = false;
boolean newCall = false;
boolean newCallR = false;
boolean newNote = false;
boolean newBuzz = false;

byte hours = 0;
byte minutes = 0;
byte seconds = 0;
byte day = 0;
byte date = 0;
byte month = 0;
int year = 0;

int k,j,n1,n2,n3,n4,n5,n6,n7,n8,N1,N2,N3,N4,N5,N6,N7,N8 = 0;
float x1,x2,ans = 0.0;

char DateBuffer[30];
char* TimeStorage [6];
char* vout;

String monthw;
String number;
String numberR;
String NoteS;
String message; //Variable for SMS messages
String blReceived; //Storage for strings received from bluetooth

char msg[150]; //Char array for SMS
char numb[15];
char numbR[15];
char note[300];
String op[4]={"+","-","*","/"};

byte menuSelection = 0; //Menu
byte menuSelections = 0; //Settings
byte menuSelectiona = 0; //Apps
byte len; //Length of message
byte len1;
byte len2;
byte l;

static unsigned long lastTick = 0;

//U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST);
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST); // I2C / TWI
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST);
//U8GLIB_SH1106_128X64_2X u8g(13, 11, 10, 9,8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8

void setup(void) {
// flip screen, if required
//u8g.setRot180();

pinMode(nextButton,INPUT); //Set digital pins as inputs
pinMode(previousButton,INPUT);
pinMode(menuButton,INPUT);
pinMode(mot,OUTPUT);
pinMode(buzz,OUTPUT);

Serial.begin(9600);
bluetooth.begin(9600);

digitalWrite(nextButton,HIGH); //Enable internal pull up on all buttons
digitalWrite(previousButton,HIGH);
digitalWrite(menuButton,HIGH);
digitalWrite(mot,HIGH);
delay(500);
digitalWrite(mot,LOW);
drawStartUp();

delay(4000);

}//end of setup

void loop() {
int k,j,n1,n2,n3,n4,n5,n6,n7,n8,N1,N2,N3,N4,N5,N6,N7,N8 = 0;
float x1,x2,ans = 0.0;
t++;
if(t>160)
{
sleep();
}
if(digitalRead(menuButton)==LOW)
t=0;
if(bluetooth.available() > 0 /&& bluetooth.find("(")/)
{
blReceived = bluetooth.readString();
if(blReceived.startsWith("1")) //1 is the preamble date
{
digitalWrite(mot,HIGH);
delay(1000);
digitalWrite(mot,LOW);
seconds++;
blReceived.toCharArray(DateBuffer,blReceived.length()+1);
vout = strtok(DateBuffer,",");
for(int i=0;i<=6;i++)
{
//if(TimeStorage[i] = NULL)
//{Serial.println("Exited Loop");
// break;}
TimeStorage[i] = strtok(NULL,",");
delay(10);
}
//int example = bluetooth.parseInt();
day = atoi(TimeStorage[0] - 1);
date = atoi(TimeStorage[1]);
month = atoi(TimeStorage[2]);
year = atoi(TimeStorage[3]);
hours = atoi(TimeStorage[4]);
minutes = atoi(TimeStorage[5]);
seconds = atoi(TimeStorage[6]);
blReceived="";
t=0;
}
else if (blReceived.startsWith("2"))
{
digitalWrite(mot,HIGH);
delay(1000);
digitalWrite(mot,LOW);
seconds++;
newMessage = true;
message = blReceived;
//sms();
//delay(300000);
blReceived="";
t=0;
}
else if (blReceived.startsWith("3"))
{
digitalWrite(mot,HIGH);
delay(1000);
digitalWrite(mot,LOW);
seconds++;
newCall = true;
number = blReceived;
//num();
//delay(300000);
blReceived="";
t=0;
}
else if (blReceived.startsWith("4"))
{
digitalWrite(mot,HIGH);
delay(1000);
digitalWrite(mot,LOW);
newCallR = true;
numberR = blReceived;
t=0;
u8g.firstPage();
do
{
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(0,20);
u8g.print("Calling...");
u8g.setPrintPos(0,40);
u8g.print(numberR);
len2 = numberR.length();

  number.toCharArray(numbR, len2+1);
  //Serial.println(len2);
  if(len2<15)
  {
     //Serial.println("If");
     for (int i = 0;(i-1)<len2;i++)
     {
        //Serial.println("Enter for loop");
        u8g.setPrintPos(i*8,30);
        u8g.print(numbR[i-15]);
        delay(10);
        if(numbR[i-16] == '\0')
        { 
           //Serial.println("Break!!");
           break;
           //delay(3000);
        }
     }
  }
Enter fullscreen mode Exit fullscreen mode

}
while (u8g.nextPage());
blReceived="";
delay(15000);
seconds=seconds+15;
newCallR = false;
}
else if (blReceived.startsWith("5"))
{
digitalWrite(mot,HIGH);
delay(1000);
digitalWrite(mot,LOW);
seconds++;
newNote = true;
NoteS = blReceived;
//notes();
//delay(300000);
blReceived="";
t=0;
}
else if (blReceived.startsWith("6"))
{
newBuzz = true;
Buzz();
blReceived="";
t=0;
}

/Serial.println(day-1);
Serial.println(date);
Serial.println(month);
Serial.println(year);
Serial.println(hours);
Serial.println(minutes);
Serial.println(seconds);
/
} //end of if for datetime

/Serial.println(day-1);
Serial.println(date);
Serial.println(month);
Serial.println(year);
Serial.println(hours);
Serial.println(minutes);
Serial.println(seconds);
/

/*else if(bluetooth.available() > 0 && bluetooth.find("CMD")==true)
{
Serial.println("ENTERED MESSAGE");
message = bluetooth.readString();
Serial.println(message);
//delay(300000);
}
*/

if(digitalRead(previousButton)==LOW && digitalRead(nextButton)==LOW) //button is activated
{
seconds=seconds+4;

if(menuShow == false) //To toggle the menu states
{
menuShow = true;
delay(100);
menu(); //Get back the menu selection number

if(menuSelection == 4)
{
seconds=seconds+4;
delay(100);
menuSelection = 0;
while(digitalRead(menuButton)== HIGH)
{
HA();
delay(10);
}
}
if(menuSelection == 3)
{
seconds=seconds+4;
settings();
if(menuSelections == 2)
{
seconds=seconds+4;
delay(100);
menuSelections=0;
delay(100);
while(digitalRead(menuButton)== HIGH)
{
notice();
}
delay(100);
}
if(menuSelections == 3)
{
seconds=seconds+4;
delay(100);
menuSelections=0;
while(digitalRead(menuButton)==HIGH)
{
torch();
delay(10);
}
}
if(menuSelections == 4)
{
seconds=seconds+4;
delay(100);
menuSelections=0;
while(digitalRead(menuButton)==HIGH)
{
bluetooth.write("1");
delay(1000);
bluetooth.write("");
}
}
bluetooth.write("");
bluetooth.write("2");
bluetooth.write("");
}
if(menuSelection == 2)
{
seconds=seconds+4;
apps();
if(menuSelectiona == 2)
{

seconds=seconds+4;
delay(100);
menuSelectiona = 0;
while(digitalRead(menuButton)==HIGH)
{
Calc();
}
bluetooth.write("");

}

    if(menuSelectiona == 3)
    {
       seconds=seconds+4;
       delay(100);
       menuSelectiona = 0;
       while(digitalRead(menuButton)== HIGH)
       {sms();}
       delay(100);
    }
    if(menuSelectiona == 4)
    {
       seconds=seconds+4;
       delay(100);
       menuSelectiona = 0;
       while(digitalRead(menuButton)== HIGH)
       {call();}
       delay(100);
    }
 }
Enter fullscreen mode Exit fullscreen mode

}
if(menuShow == true)
{
menuShow = false;
delay(100);

}
}//end of if
advanceTime();
delay(30);
}//end of loop

void sleep()
{
u8g.firstPage();
do{}
while(u8g.nextPage());
}

void advanceTime()
{
if(millis()-lastTick>950) //somehow
{
lastTick = millis();
seconds++;
}

if (seconds > 59)
{
minutes++;
seconds = 0;
}

if (minutes >59)
{
hours++;
minutes = 0;
}

if (hours > 23)
{
hours = 0;
minutes = 0;
date+=1;
}
draw();

}

//**------------------U8Glib Functions------------------**
void HA()
{
u8g.firstPage();

do {
bluetooth.write("3");
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(0,10);
u8g.print("Home Automation");
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(30,10);
u8g.print("In Development");
bluetooth.write("");
} while( u8g.nextPage() );
}

void Buzz()
{
while(c<5)
{
for(i=1;i<256;i++)
{
analogWrite(buzz,i);
delay(3.92);
}
for(i=256;i>0;i--)
{
analogWrite(buzz,i);
delay(3.92);
}
c++;
}
c=0;
newBuzz=false;
}

void drawStartUp()
{
u8g.firstPage();
do
{
//u8g_prepare();
u8g.setColorIndex(0);
u8g.drawBox(0,0,127,63);
u8g.setColorIndex(1);
u8g.setFont(u8g_font_7x14r);
u8g.setPrintPos(5,10);
u8g.print("Developed By:-");
u8g.setFont(u8g_font_fur17r);
u8g.setPrintPos(10,38);
u8g.print("USER");
u8g.setFont(u8g_font_7x14r);
u8g.setPrintPos(5,62);
u8g.print("V402");
}
while(u8g.nextPage());
} //end of drawStartUp

void menu()
{

u8g.setColorIndex(1);
//u8g.drawCircle(20,20,14);
menuSelection = 1;
while(digitalRead(menuButton) == HIGH)
{
if(digitalRead(nextButton) == LOW)
{
delay(20);
menuSelection++;
delay(50);
}

 if(digitalRead(previousButton) == LOW)
 {
    delay(20);
    menuSelection--;
    delay(50);
 }

 if(menuSelection > 4)
 {menuSelection = 1;}

 if(menuSelection < 1)
 {menuSelection = 4;}
 //draw picture here
 drawMenu();

 delay(50); //For debouncing

 //draw menus here
Enter fullscreen mode Exit fullscreen mode

}//end of while loop
}//end of menu

void drawMenu()
{
u8g.firstPage();
do
{
u8g.setFont(u8g_font_6x10r);
u8g.setPrintPos(30,8);
u8g.print("--- Menu ---");
//u8g.setPrintPos(0,10);
//u8g.print(menuSelection);
u8g.drawFrame(0,(menuSelection*13)-3,128,13); //Box height is 13 pixels
u8g.drawLine(0,10,128,10);

  //Draw menu options
  u8g.drawStr(3,20,"Return");
  u8g.drawStr(3,20+13,"Apps");
  u8g.drawStr(3,20+13+13,"Settings");
  u8g.drawStr(3,20+13+13+13,"Home Auto(Beta)");
  //u8g.drawStr(3,20+13+13+13,"More");   
Enter fullscreen mode Exit fullscreen mode

}
while(u8g.nextPage());
}

void apps()
{
u8g.setColorIndex(1);
//u8g.drawCircle(20,20,14);
menuSelectiona = 1;
delay(200);
while(digitalRead(menuButton) == HIGH)
{
if(digitalRead(nextButton) == LOW)
{
delay(20);
menuSelectiona++;
Serial.println("Up");
delay(50);
}

  if(digitalRead(previousButton) == LOW)
  {
     delay(20);
     menuSelectiona--;
     delay(50);
  }

  if(menuSelectiona > 4)
  {menuSelectiona = 1;}

  if(menuSelectiona < 1)
  {menuSelectiona = 4;}
  //draw picture here
drawApps();
delay(50); //For debouncing
Enter fullscreen mode Exit fullscreen mode

}//end of while loop
}

void notice()
{
u8g.firstPage();
do
{
u8g.setFont(u8g_font_6x10r);
//u8g.print(NoteS);
l = NoteS.length();
NoteS.toCharArray(note, l+1);
//Serial.println(len);
if(l>0)
{
for(i=0;i<20;i++)
{
u8g.setPrintPos(i*6,8);
u8g.print(note[i]);
delay(10);
}
}
if(l>20)
{
for(i=20;i<40;i++)
{
u8g.setPrintPos((i-20)*6,17);
u8g.print(note[i]);
delay(10);
}
}
if(l>40)
{
for(i=40;i<60;i++)
{
u8g.setPrintPos((i-40)*6,26);
u8g.print(note[i]);
delay(10);
}
}
if(l>60)
{
for(i=60;i<80;i++)
{
u8g.setPrintPos((i-60)*6,35);
u8g.print(note[i]);
delay(10);
}
}
if(l>80)
{
for(i=80;i<100;i++)
{
u8g.setPrintPos((i-80)*6,43);
u8g.print(note[i]);
delay(10);
}
}
if(l>100)
{
for(i=100;i<120;i++)
{
u8g.setPrintPos((i-100)*6,51);
u8g.print(note[i]);
delay(10);
}
}
if(l>120)
{
for(i=120;i<140;i++)
{
u8g.setPrintPos((i-120)*6,59);
u8g.print(note[i]);
delay(10);
}
}
}
while (u8g.nextPage());
delay(30);
newNote = false;
}

void torch()
{
u8g.firstPage();
do{u8g.drawBox(0,0,127,63);}
while(u8g.nextPage());
}

void drawApps()
{
u8g.firstPage();
do
{
u8g.setFont(u8g_font_6x10r);
u8g.setPrintPos(5,8);
u8g.print("--- Applications ---");
//u8g.setPrintPos(0,10);
//u8g.print(menuSelection);
u8g.drawFrame(0,(menuSelectiona*13)-3,128,13); //Box height is 13 pixels
u8g.drawLine(0,10,128,10);

  //Draw menu options
  u8g.drawStr(3,20,"Return");
  u8g.drawStr(3,20+13,"CALC");
  u8g.drawStr(3,20+13+13,"SMS");
  u8g.drawStr(3,20+13+13+13,"CALLS");
  //u8g.drawStr(3,20+13+13+13,"More");
Enter fullscreen mode Exit fullscreen mode

}

while(u8g.nextPage());
}

void settings()
{
u8g.setColorIndex(1);
//u8g.drawCircle(20,20,14);
menuSelections = 1;
delay(200);
while(digitalRead(menuButton) == HIGH)
{

if(digitalRead(nextButton) == LOW)
{
delay(20);
menuSelections++;
Serial.println("Up");
delay(50);
}

  if(digitalRead(previousButton) == LOW)
  {
     delay(20);
     menuSelections--;
     delay(50);
  }

  if(menuSelections > 4)
  {menuSelections = 1;}

  if(menuSelections < 1)
  {menuSelections = 4;}
  //draw picture here
  drawSettings();

  delay(50); //For debouncing
Enter fullscreen mode Exit fullscreen mode

}//end of while loop
}

void sms()
{
u8g.firstPage();
do
{
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(0,10);
u8g.print(message);
len = message.length();

  message.toCharArray(msg, len+1);
  //Serial.println(len);
  if(len>16)
  {
     //Serial.println("If");
     for (int i = 0;(i-1)<len;i++)
     {
        //Serial.println("Enter for loop");
        u8g.setPrintPos(i*8,30);
        u8g.print(msg[i+16]);
        delay(10);
        if(msg[i+17] == '\0')
        { 
           //Serial.println("Break!!");
           break;
           //delay(3000);
        }
     }
  }

  if(len>32)
  {
     //Serial.println("If");
     for (int i = 0;(i-1)<len;i++)
     {
        //Serial.println("Enter for loop");
        u8g.setPrintPos(i*8,50);
        u8g.print(msg[i+32]);
        delay(10);
        if(msg[i+33] == '\0')
        { 
           //Serial.println("Break!!");
           break;
           //delay(3000);
        }
     }
  }
Enter fullscreen mode Exit fullscreen mode

}
while (u8g.nextPage());
delay(30);
newMessage = false;
}

void call()
{
u8g.firstPage();
do
{
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(0,10);
u8g.print(number);
len1 = number.length();

  number.toCharArray(numb, len1+1);
  //Serial.println(len1);
  if(len1<15)
  {
     //Serial.println("If");
     for (int i = 0;(i-1)<len1;i++)
     {
        //Serial.println("Enter for loop");
        u8g.setPrintPos(i*8,30);
        u8g.print(numb[i-15]);
        delay(10);
        if(numb[i-16] == '\0')
        { 
           //Serial.println("Break!!");
           break;
           //delay(3000);
        }
     }
  }
Enter fullscreen mode Exit fullscreen mode

}
while (u8g.nextPage());
delay(30);
newCall = false;
}

void drawSettings()
{
u8g.firstPage();
do
{
u8g.setFont(u8g_font_6x10r);
u8g.setPrintPos(15,8);
u8g.print("--- Settings ---");
//u8g.setPrintPos(0,10);
//u8g.print(menuSelection);
u8g.drawFrame(0,(menuSelections*13)-3,128,13); //Box height is 13 pixels
u8g.drawLine(0,10,128,10);

  //Draw menu options
  u8g.drawStr(3,20,"Return");
  u8g.drawStr(3,20+13,"Notes");
  u8g.drawStr(3,20+13+13,"Torch");
  u8g.drawStr(3,20+13+13+13,"Find My Phone");
Enter fullscreen mode Exit fullscreen mode

}
while(u8g.nextPage());
}

void CalcPrintdata()
{
u8g.setPrintPos(50,25);
u8g.print(n3);
u8g.setPrintPos(40,25);
u8g.print(n4);
u8g.setPrintPos(30,25);
u8g.print(n5);
u8g.setPrintPos(20,25);
u8g.print(n6);
u8g.setPrintPos(60,25);
u8g.print(".");
u8g.setPrintPos(70,25);
u8g.print(n7);
u8g.setPrintPos(80,25);
u8g.print(n8);
u8g.setPrintPos(3,37);
u8g.print(op[k]);
u8g.setPrintPos(50,37);
u8g.print(N3);
u8g.setPrintPos(40,37);
u8g.print(N4);
u8g.setPrintPos(30,37);
u8g.print(N5);
u8g.setPrintPos(20,37);
u8g.print(N6);
u8g.setPrintPos(60,37);
u8g.print(".");
u8g.setPrintPos(70,37);
u8g.print(N7);
u8g.setPrintPos(80,37);
u8g.print(N8);
u8g.setPrintPos(5,46);
u8g.print("---------------");

u8g.setPrintPos(5,54);
u8g.print(ans);
}

void Calc()
{
u8g.firstPage();
do{
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(0,10);
u8g.print("Calculator:-");
if(digitalRead(previousButton) == LOW)
{
j++;
delay(300);
if(j>12)
j = 0;
}
if(digitalRead(nextButton)==LOW && digitalRead(previousButton)==LOW)
{
j=13;
delay(300);
}
if(j==0)
{
CalcPrintdata();
if(digitalRead(nextButton) == LOW)
{
n6++;
delay(300);
}
if(n6>9)
n6=0;
}
if(j==1)
{
CalcPrintdata();
if(digitalRead(nextButton) == LOW)
{
n5++;
delay(300);
}
if(n5>9)
n5=0;
}
if(j==2)
{
CalcPrintdata();
if(digitalRead(nextButton) == LOW)
{
n4++;
delay(300);
}
if(n4>9)
n4=0;
}
if(j==3)
{
CalcPrintdata();
if(digitalRead(nextButton) == LOW)
{
n3++;
delay(300);
}
if(n3>9)
n3=0;
}
if(j==4)
{
CalcPrintdata();
if(digitalRead(nextButton) == LOW)
{
n7++;
delay(300);
}
if(n7>9)
n7=0;
}
if(j==5)
{
CalcPrintdata();
if(digitalRead(nextButton) == LOW)
{
n8++;
delay(300);
}
if(n8>9)
n8=0;
}
if(j==6)
{
CalcPrintdata();
if(digitalRead(nextButton) == LOW)
{
k++;
delay(300);
}
if(k>3)
k=0;
}
if(j==7)
{
CalcPrintdata();
if(digitalRead(nextButton) == LOW)
{
N6++;
delay(300);
...

Top comments (0)