Hello Guys,
I am programming an Atmega32 with an Arduino as ISP using the MightyCore board library. My project involves the use of a seven segment of type TM1637.
I looked for a library for the display and installed one. The display works perfectly with an Arduino Uno or even with an Atmega32 provided I use a different board library (not the MightyCore like my case).
Since I prefer working with MightyCore, could you please advise on how to go about it?
the TM1637 doesn't show any segment when using the MightyCore.
FYI, All connections are ok.
The code I use is found below.
Best,
I am programming an Atmega32 with an Arduino as ISP using the MightyCore board library. My project involves the use of a seven segment of type TM1637.
I looked for a library for the display and installed one. The display works perfectly with an Arduino Uno or even with an Atmega32 provided I use a different board library (not the MightyCore like my case).
Since I prefer working with MightyCore, could you please advise on how to go about it?
the TM1637 doesn't show any segment when using the MightyCore.
FYI, All connections are ok.
The code I use is found below.
Best,
Code:
#include <ShiftRegister74HC595.h>
#include <Arduino.h>
#include <TM1637Display.h>
// TM1637
#define CLK 25
#define DIO 26
TM1637Display lift_display(CLK, DIO);
// Buttons
#define BT_UP 28
#define BT_DW 27
#define BT_INS_UP 30
#define BT_INS_DW 31
// Calls
#define CALL_F0 21
#define CALL_F1 22
#define CALL_F2 23
#define CALL_F3 24
// Limits Switches
#define DSS 2
#define USS 1
#define DLS 0
#define ULS 29
// Sensors
#define PHOTOCELL2 12
#define EXT_ALARM1 7
#define EXT_ALARM2 6
#define THERMO 5
#define DOOR_OPEN_BT 4
#define PHOTOCELL1 3
//Security
#define SC2 16
#define SC1 17
#define SC3 18
#define SC4 19
#define SC5 20
// Shift register
#define OUT_DATA 15
#define OUT_STB 14
#define OUT_CLK 13
ShiftRegister74HC595 lift(1, OUT_DATA, OUT_CLK, OUT_STB);
unsigned int current_floor=0, destination_floor;
uint8_t unknown_floor[] = {0b01000000,0b01000000, 0b01000000, 0b01000000};
bool incremented = LOW;
bool goup = LOW;
bool godown = LOW;
bool unknown = LOW;
int e_floor = 0;
int e_difference = 0;
int e_destination = 0;
// State change function
int buttonPushCounter_DSS = 1; // counter for the number of button presses
int buttonState_DSS = 0; // current state of the button
int lastButtonState_DSS = 0; // previous state of the button
///////////////////
int buttonPushCounter_USS = 1; // counter for the number of button presses
int buttonState_USS = 0; // current state of the button
int lastButtonState_USS = 0; // previous state of the button
///////////////////
int buttonPushCounter_DLS = 1; // counter for the number of button presses
int buttonState_DLS = 0; // current state of the button
int lastButtonState_DLS = 0; // previous state of the button
///////////////////
int buttonPushCounter_ULS = 1; // counter for the number of button presses
int buttonState_ULS = 0; // current state of the button
int lastButtonState_ULS = 0; // previous state of the button
uint8_t off[] = { B00001000 }; ///// not running
uint8_t DW_LOW[] = { B01011000 }; //// Low speed DOWN
uint8_t UP_LOW[] = { B01101000 }; //// Low speed UP
uint8_t UP_HIGH[] = { B10101000 }; //// High speed UP
uint8_t DW_HIGH[] = { B10011000 }; //// High speed DOWN
void setup(){
pinMode(BT_UP, INPUT); ////Inputs
pinMode(BT_DW, INPUT);
pinMode(BT_INS_UP, INPUT);
pinMode(BT_INS_DW, INPUT);
pinMode(CALL_F0, INPUT);
pinMode(CALL_F1, INPUT);
pinMode(CALL_F2, INPUT);
pinMode(CALL_F3, INPUT);
pinMode(USS, INPUT);
pinMode(DSS, INPUT);
pinMode(DLS, INPUT);
pinMode(ULS, INPUT);
pinMode(PHOTOCELL2 , INPUT);
pinMode(EXT_ALARM1, INPUT);
pinMode(EXT_ALARM2 , INPUT);
pinMode(THERMO , INPUT);
pinMode(DOOR_OPEN_BT , INPUT);
pinMode(PHOTOCELL1, INPUT);
pinMode(SC2, INPUT);
pinMode(SC1, INPUT);
pinMode(SC3, INPUT);
pinMode(SC4, INPUT);
pinMode(SC5, INPUT);
pinMode(DIO, OUTPUT); //// Outputs
pinMode(CLK, OUTPUT);
pinMode(OUT_DATA, OUTPUT);
pinMode(OUT_STB, OUTPUT);
pinMode(OUT_CLK, OUTPUT);
Serial.begin(9600);
lift_display.setBrightness(7);
lift.setAll(off);
if( digitalRead(USS)== LOW && digitalRead(DSS)== LOW && digitalRead(ULS)== HIGH && digitalRead(DLS)== LOW )
{lift_display.showNumberDec(0);
current_floor=0;}
else if ( digitalRead(USS)== LOW && digitalRead(DSS)== LOW && digitalRead(ULS)== LOW && digitalRead(DLS)== HIGH )
{ lift_display.showNumberDec(2);
current_floor=2;}
else
{
lift_display.setSegments(unknown_floor);
unknown=HIGH;
}
if(unknown == HIGH) {
while( digitalRead(DLS)== HIGH)
lift.setAll(DW_HIGH);
}
while( digitalRead(DSS)== HIGH)
lift.setAll(DW_LOW);
lift_display.showNumberDec(0);
current_floor=0;
}
void loop()
{
//lift_display.showNumberDec(current_floor);}
buttonPushCounter_DSS = 1;
buttonPushCounter_USS = 1;
lift.setAll(off);
boolean call = digitalRead(CALL_F0) || digitalRead(CALL_F1) || digitalRead(CALL_F2) || digitalRead(CALL_F3);
if ( digitalRead(CALL_F0)== HIGH){
destination_floor=0;
e_destination=0;}
else if(digitalRead(CALL_F1) == HIGH){
destination_floor=1;
e_destination=1;}
else if(digitalRead(CALL_F2) == HIGH ){
destination_floor=2;
e_destination=2;}
int difference = destination_floor - current_floor;
if ( difference > 0){
goup= HIGH;
godown=LOW;}
else if ( difference < 0){
goup= LOW;
godown=HIGH;}
Serial.print("current_floor is");
Serial.println(current_floor, DEC);
Serial.print("Destination floor is");
Serial.println(destination_floor, DEC);
if ( current_floor == 1) {
e_floor=1; }
//delay(250);
switch (call) {
case HIGH:
lift_display.showNumberDec(current_floor);
while (goup) { //// lift is going up
Serial.print("current_floor is");
Serial.println(current_floor, DEC);
Serial.print("Destination floor is");
Serial.println(destination_floor, DEC);
Serial.print("E-floor is");
Serial.println(e_floor, DEC);
//delay(250);
difference = destination_floor - current_floor;
e_difference = e_destination - e_floor;
lift_display.showNumberDec(current_floor);
state_change_DSS(DSS);
state_change_USS(USS);
Serial.print("DSS= ");
Serial.print(buttonPushCounter_DSS, DEC);
Serial.print(" USS= ");
Serial.println(buttonPushCounter_USS, DEC);
if( digitalRead(incremented) == HIGH)
Serial.println(" incremented is high ");
else if ( digitalRead(incremented) == LOW)
Serial.println(" incremented is low ");
if((buttonPushCounter_DSS % 2 == 0 && buttonPushCounter_USS % 2 == 0 && e_difference > 1) ) {
if(!incremented){
e_floor++;
incremented = HIGH;}
lift_display.showNumberDec(e_floor);
}
else if((buttonPushCounter_DSS % 4 == 0 && buttonPushCounter_USS % 4 == 0 && difference > 1) ) {
if(!incremented){
current_floor=2;
incremented = HIGH;}
lift_display.showNumberDec(current_floor);
}
else if((buttonPushCounter_DSS % 2 == 0 && buttonPushCounter_USS % 2 == 0 && difference == 1) ) {
lift.setAll(UP_LOW);
if(!incremented){
current_floor++;
incremented = HIGH;}
lift_display.showNumberDec(current_floor);
}
else if((buttonPushCounter_DSS % 2 == 0 && buttonPushCounter_USS % 2 == 0 && difference == 0) || (buttonPushCounter_DSS % 3 == 0 && buttonPushCounter_USS % 2 == 0 && difference == 0) || (buttonPushCounter_DSS % 5 == 0 && buttonPushCounter_USS % 4 == 0 && difference == 0)){
lift.setAll(UP_LOW);
incremented = LOW;
}
else if((buttonPushCounter_DSS % 3 == 0 && buttonPushCounter_USS % 3 == 0 && difference == 0) || (buttonPushCounter_DSS % 5 == 0 && buttonPushCounter_USS % 5 == 0 && difference == 0)) {
lift.setAll(off);
lift_display.showNumberDec(current_floor);
incremented = LOW;
goup = LOW;
}
else {
incremented = LOW;
lift.setAll(UP_HIGH);
}}
while (godown) { //// lift is going down
Serial.print("current_floor is");
Serial.println(current_floor, DEC);
Serial.print("Destination floor is");
Serial.println(destination_floor, DEC);
Serial.print("E-floor is");
Serial.println(e_floor, DEC);
//delay(250);
difference = destination_floor - current_floor;
e_difference = e_destination - e_floor;
lift_display.showNumberDec(current_floor);
state_change_DSS(DSS);
state_change_USS(USS);
Serial.print("DSS= ");
Serial.print(buttonPushCounter_DSS, DEC);
Serial.print(" USS= ");
Serial.println(buttonPushCounter_USS, DEC);
if( digitalRead(incremented) == HIGH)
Serial.println(" incremented is high ");
else if ( digitalRead(incremented) == LOW)
Serial.println(" incremented is low ");
if((buttonPushCounter_DSS % 2 == 0 && buttonPushCounter_USS % 2 == 0 && e_difference < -1) ) {
if(!incremented){
e_floor--;
incremented = HIGH;}
lift_display.showNumberDec(e_floor);
}
else if((buttonPushCounter_DSS % 4 == 0 && buttonPushCounter_USS % 4 == 0 && difference < -1) ) {
if(!incremented){
current_floor=0;
incremented = HIGH;}
lift_display.showNumberDec(current_floor);
}
else if((buttonPushCounter_DSS % 2 == 0 && buttonPushCounter_USS % 2 == 0 && difference == -1) ) {
lift.setAll(DW_LOW);
if(!incremented){
current_floor--;
incremented = HIGH;}
lift_display.showNumberDec(current_floor);
}
else if((buttonPushCounter_DSS % 2 == 0 && buttonPushCounter_USS % 2 == 0 && difference == 0) || (buttonPushCounter_USS % 3 == 0 && buttonPushCounter_DSS % 2 == 0 && difference == 0) || (buttonPushCounter_USS % 5 == 0 && buttonPushCounter_DSS % 4 == 0 && difference == 0)){
lift.setAll(DW_LOW);
incremented = LOW;}
else if((buttonPushCounter_DSS % 3 == 0 && buttonPushCounter_USS % 3 == 0 && difference == 0) || (buttonPushCounter_DSS % 5 == 0 && buttonPushCounter_USS % 5 == 0 && difference == 0)) {
lift.setAll(off);
lift_display.showNumberDec(current_floor);
incremented = LOW;
godown = LOW;
}
else {
incremented = LOW;
lift.setAll(DW_HIGH);
}}
break;
case LOW:
lift.setAll(off);
break;
}}
/////////////////////////////// State Change functions DSS
int state_change_DSS(int input_pin)
{
buttonState_DSS = digitalRead(input_pin);
if (buttonState_DSS != lastButtonState_DSS) {
if (buttonState_DSS == LOW) {
buttonPushCounter_DSS++;}
delay(50);
}
lastButtonState_DSS = buttonState_DSS;
return buttonPushCounter_DSS;
}
////////////////////////// USS
int state_change_USS(int input_pin)
{
buttonState_USS = digitalRead(input_pin);
if (buttonState_USS != lastButtonState_USS) {
if (buttonState_USS == LOW) {
buttonPushCounter_USS++;}
delay(50);
}
lastButtonState_USS = buttonState_USS;
return buttonPushCounter_USS;
}
/////////////////////////// DLS
int state_change_DLS(int input_pin)
{
buttonState_DLS = digitalRead(input_pin);
if (buttonState_DLS != lastButtonState_DLS) {
if (buttonState_DLS == LOW) {
buttonPushCounter_DLS++;}
delay(50);
}
lastButtonState_DLS = buttonState_DLS;
return buttonPushCounter_DLS;
}
//////////////////////// ULS
int state_change_ULS(int input_pin)
{
buttonState_ULS = digitalRead(input_pin);
if (buttonState_ULS != lastButtonState_ULS) {
if (buttonState_ULS == LOW) {
buttonPushCounter_ULS++;}
delay(50);
}
lastButtonState_ULS = buttonState_ULS;
return buttonPushCounter_ULS;
}