bonjour mike118,
j'ai modifiè le code ,et grand surprise , le moteur ne bouge pas .
je te mets le code pour que tu puisses vérifier que je n'ai rien oubliè .
je te mets également la photo de mon entrainement turntable .
total de la couronne de dents 140 dents combien tu penses que je dois mettre de dents sur l'axe du moteur .
je vais utiliser une couronne parce que j'aimerai utiliser le centre pour l'écoulement de l'eau puisque je vais poser un arbre sur le turntable .
merci pour ton aide ,Michel
#include <Wire.h>
#include "RTClib.h"
#include <Stepper.h>
#include <Encoder.h> // from http://www.pjrc.com/teensy/td_libs_Encoder.html
Encoder knob(3, 4); //encoder connected to pins 2 and 3 (and ground)// D2 SEEDSTUDIO shield
#include <TimeLib.h>
#include <TimeLord.h>
#include <EEPROM.h>
const float LATITUDE = 43.70, LONGITUDE = 7.25; // Nice Sun
const int TIMEZONE = + 1;
int r = 35;//cercle drawLine
int r_1 = 35;//drawbitmap
int angle = 0;
int x1=57;// drawbitmap rattrapage width 65-8 = 57
int y1=43;// drawbitmap rattrapage height 50-8 = 42
int x0=65;// drawLine
int y0=50;// drawLine
int sun;
int alfa=0;
int degre = 0;
//int backlight = 6; //backlight control pin 6
/* variables stepper */
const int nbrepas360 = 64; // Fixe le nombre de pas pour faire un tour complet, c'est-à-dire 360°.
Stepper monmoteur (nbrepas360, 8, 9, 10, 11); // Initialise la librairie Stepper.h
//int cptepas = 0 ;
int alfa_1 = 0;
float position_cible;
float degrees_pas = 1;
int cpte_pas_cible;
#define u8g_logo_width 16
#define u8g_logo_height 16
#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
#define Serial SerialUSB
#endif
RTC_DS1307 RTC;
char daysOfTheWeek[7][12] = {"Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"};
#include "U8glib.h"
//U8GLIB_ST7920_128X64 u8g(13, 11, 12, U8G_PIN_NONE);//U8GLIB_ST7920_128X64_1X u8g(7, 6, 5 ,8); //Enable, RW, RS, RESET
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);
int Timer = 0;
int Minutt = 0;
int Sekund = 0;
float Vinkel = 0;
int an = 0;
int luna = 0;
int zi = 0;
int zis = 0;
//the variables provide the holding values for the set clock routine
int setyeartemp;
int setmonthtemp;
int setdaytemp;
int setoretemp;
int setzitemp;
int setminstemp;
int setsecs = 0;
// maximum number of days in the given month
int TimeMins; // number of seconds since midnight
int TimerMode = 2; //mode 0=Off 1=On 2=Auto
int TimeOut = 10;
int TimeOutCounter;
// These variables are for the push button routine
int buttonstate = 0; //flag to see if the button has been pressed, used internal on the subroutine only
int pushlengthset = 1500; // value for a long push in mS
int pushlength = pushlengthset; // set default pushlength
int pushstart = 0;// sets default push value for the button going low
int pushstop = 0;// sets the default value for when the button goes back high
int Sunrise, Sunset; //sunrise and sunset expressed as minute of day (0-1439)
TimeLord myLord; // TimeLord Object, Global variable
byte sunTime[] = {0, 0, 0, 1, 1, 13}; // 17 Oct 2013
int SunriseHour, SunriseMin, SunsetHour, SunsetMin;
int knobval; // value for the rotation of the knob
boolean buttonflag = false; // default value for the button flag
int backlight = 6;//backlight control pin 6
#include <stdlib.h>
char tmp_string[8];
int max_day(){
int ma_valeur_de_maxday=0;
DateTime now = RTC.now();
if (now.month() == 4 || now.month() == 5 || now.month() == 9 || now.month() == 11){ //30 jours = Septembre, Avril, Juin, Novembre.
ma_valeur_de_maxday = 30;
}
else {
ma_valeur_de_maxday = 31; //... all the others have 31
}
if (now.month() == 2 && now.year() % 4 == 0){ //... Exception Fevrier = 28 jours , ou 29 jours année bissextile.
ma_valeur_de_maxday = 29;
}
if (now.month() == 2 && now.year() % 4 != 0){
ma_valeur_de_maxday = 28;
}
return ma_valeur_de_maxday;
}
void turntable(void) {
DateTime now = RTC.now();
/* center */
int x2=128/2;
int y2=64/2;
/* radius */
int r2=22;
/* angle*/
alfa_1 =360*now.day()/max_day();
u8g.setPrintPos(1,60);
u8g.print(alfa_1);
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(30,60);
u8g.print(EEPROM.read(17));//cpte_pas_cible
u8g.setPrintPos(90,60);
u8g.print(EEPROM.read(18));//cptepas
/* affichage maxday */
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(110,30 );
u8g.print(max_day());
u8g.setPrintPos(62,9);
u8g.print("0");
u8g.setPrintPos(90,32);
u8g.print("90");
u8g.setPrintPos(56,64);
u8g.print("180");
u8g.setPrintPos(22,32);
u8g.print("270");
u8g.drawLine(x2,y2, x2+r2*sin(1*alfa_1*2*3.14/360), y2-r2*cos(1*alfa_1*2*3.14/360));
u8g.drawCircle(x2, y2, r2);
}
void moteur_avance_2_pas() {
monmoteur.step(2);
}
void draw(void) {
DateTime now = RTC.now();
/*Timelord initialisation*/
myLord.TimeZone(TIMEZONE * 60);
myLord.Position(LATITUDE, LONGITUDE);
sunTime[3] = now.day(); // Give Timelord the current date
sunTime[4] = now.month();
sunTime[5] = now.year();
myLord.SunRise(sunTime); // Computes Sun Rise.
Sunrise = sunTime[2] * 60 + sunTime[1]; // Sunrise returned in minutes past midnight
SunriseHour = sunTime[2];
SunriseMin = sunTime [1];
sunTime[3] = now.day(); // Uses the Time library to give Timelord the current date
sunTime[4] = now.month();
sunTime[5] = now.year();
myLord.SunSet(sunTime); // Computes Sun Set.
Sunset = sunTime[2] * 60 + sunTime[1]; // Sunset returned in minutes past midnight
SunsetHour = sunTime[2];
SunsetMin = sunTime [1];
u8g.setFont(u8g_font_6x13);
u8g.setPrintPos(2,10);
if (zi < 10) u8g.print("0");
u8g.print(zi);
u8g.print("/");
if (luna < 10) u8g.print("0");
u8g.print(luna);
u8g.print("/");
u8g.setPrintPos(40,10);
u8g.print(daysOfTheWeek[zis]);
u8g.setFont(u8g_font_6x13);
u8g.setPrintPos(80,10);
if (Timer < 10) u8g.print(" ");
u8g.print(Timer);
u8g.setPrintPos(93,10);
if (Sekund%2 != 1)
u8g.print(":");
u8g.setPrintPos(115,10);
u8g.setFont(u8g_font_6x10);
if(Sekund<10)u8g.print("0");
u8g.print(Sekund);
u8g.setPrintPos(100,10);
u8g.setFont(u8g_font_6x13);
if (Minutt < 10) u8g.print("0");
u8g.print(Minutt);
TimeMins = (now.hour() * 60) + now.minute();
//u8g.setPrintPos(1,60);
//u8g.print(EEPROM.read(16));
TimeMins = (now.hour() * 60) + now.minute();
if (TimeMins >= Sunrise && TimeMins <=Sunset-1) { //If it's after sunrise and before sunset, switch our relay on
digitalWrite (A3, HIGH);// cdt PONT H
//analogWrite(backlight,255);// lcd rétroéclairage On
u8g.setColorIndex(1); // Pixel On SH1106
}
else { //otherwise switch it off
digitalWrite (A3,LOW);// cdt PONT H
//analogWrite(backlight,0);// lcd rétroéclairage Off
u8g.setColorIndex(0);// Pixel Off SH1106
}
}
void setup(void) {
u8g.setContrast(0);//Config the constrast to the best effect
analogWrite(backlight,255);
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 )
u8g.setColorIndex(255); // white
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
u8g.setColorIndex(3); // max intensity
else if ( u8g.getMode() == U8G_MODE_BW )
u8g.setColorIndex(1); // pixel on
Serial.begin(9600);
Wire.begin();
if (! RTC.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
pinMode(A0,INPUT);//push button on encoder connected to A0 (and GND)
digitalWrite(A0,HIGH); //Pull button high
}
void loop(void) {
u8g.setFont(u8g_font_6x10);
DateTime now = RTC.now();
Timer = now.hour(), DEC;
Minutt = now.minute(), DEC;
Sekund = now.second(), DEC;
Serial.print(Timer);
Serial.print(':');
Serial.print(Minutt);
Serial.print(':');
Serial.print(Sekund);
Serial.print(" - ");
an = now.year(), DEC;
Serial.print(an);
Serial.print('/');
luna = now.month(), DEC;
Serial.print(luna);
Serial.print('/');
zi = now.day(), DEC;
Serial.print(zi);
Serial.print(" (");
zis = now.dayOfTheWeek();
Serial.print(daysOfTheWeek[zis]);
Serial.println(") ");
moteur_avance_2_pas();
/* picture loop*/
u8g.firstPage();
do {
draw();
turntable();
} while( u8g.nextPage() );
// rebuild the picture after some delay
delay(100);
pushlength = pushlengthset;
pushlength = getpushlength();
delay (10);
if (pushlength < pushlengthset)
{
//ShortPush ();
Serial.println("short push");
// picture loop
u8g.firstPage();
do {
draw1();
} while( u8g.nextPage() );
// rebuild the picture after some delay
delay(1000);
}
//This runs the setclock routine if the knob is pushed for a long time
if (pushlength > pushlengthset) {
Serial.println("long push");
DateTime now = RTC.now();
setyeartemp=now.year(),DEC;
setmonthtemp=now.month(),DEC;
setdaytemp=now.day(),DEC;
setoretemp=now.hour(),DEC;
setminstemp=now.minute(),DEC;
setzitemp = now.dayOfTheWeek();
setclock();
pushlength = pushlengthset;
};
} // end main loop
// subroutine to return the length of the button push.
int getpushlength()
{
buttonstate = digitalRead(A0);
if(buttonstate == LOW && buttonflag==false) {
pushstart = millis();
buttonflag = true;
};
if (buttonstate == HIGH && buttonflag==true) {
pushstop = millis ();
pushlength = pushstop - pushstart;
buttonflag = false;
};
Serial.println("_");
return pushlength;
}
void draw1(void) {
u8g.drawStr( 10, 32, "Thx to niq_ro!");
}
//sets the clock
void setclock (){
setyear ();//Annee
setmonth ();//Mois
setday ();//Jour
setzi();//semaine
setore ();//hours
setmins ();//Minutes
RTC.adjust(DateTime(setyeartemp,setmonthtemp,setdaytemp,setoretemp,setminstemp,setsecs));
CalcSun();
delay (1000);
}
int CalcSun () { //Calculates the Sunrise and Sunset times
DateTime now = RTC.now();
//Timelord initialisation
myLord.TimeZone(TIMEZONE * 60);
myLord.Position(LATITUDE, LONGITUDE);
sunTime[3] = now.day(); // Give Timelord the current date
sunTime[4] = now.month();
sunTime[5] = now.year();
myLord.SunRise(sunTime); // Computes Sun Rise.
Sunrise = sunTime[2] * 60 + sunTime[1]; // Sunrise returned in minutes past midnight
SunriseHour = sunTime[2];
SunriseMin = sunTime [1];
sunTime[3] = now.day(); // Uses the Time library to give Timelord the current date
sunTime[4] = now.month();
sunTime[5] = now.year();
myLord.SunSet(sunTime); // Computes Sun Set.
Sunset = sunTime[2] * 60 + sunTime[1]; // Sunset returned in minutes past midnight
SunsetHour = sunTime[2];
SunsetMin = sunTime [1];
}
// The following subroutines set the individual clock parameters
int setyear () {
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setyeartemp;
}
knob.write(0);
delay (50);
knobval=knob.read();
if (knobval < -1) { //bit of software de-bounce
knobval = -1;
delay (50);
}
if (knobval > 1) {
knobval = 1;
delay (50);
}
setyeartemp=setyeartemp + knobval;
if (setyeartemp < 2018) { //Year can't be older than currently, it's not a time machine.
setyeartemp = 2018;
}
//itoa(setyeartemp - 2000, tmp_string, 10); // https://www.avrfreaks.net/forum/how-do-i-print-variable-u8glib
itoa(setyeartemp, tmp_string, 10); // https://www.avrfreaks.net/forum/how-do-i-print-variable-u8glib
u8g.firstPage();
do {
u8g.drawStr( 0, 20, "Set Annee");
// u8g.drawStr( 0, 40, "20");
u8g.drawStr(25, 40, tmp_string);
} while( u8g.nextPage() );
setyear();
}
int setmonth () {
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setmonthtemp;
}
// lcd.setCursor (0,1);
knob.write(0);
delay (50);
knobval=knob.read();
if (knobval < -1) {
knobval = -1;
}
if (knobval > 1) {
knobval = 1;
}
setmonthtemp=setmonthtemp + knobval;
if (setmonthtemp < 1) {// month must be between 1 and 12
setmonthtemp = 1;
}
if (setmonthtemp > 12) {
setmonthtemp=12;
}
itoa(setmonthtemp, tmp_string, 10);
u8g.firstPage();
do {
u8g.drawStr( 0, 20, "Set Mois");
u8g.drawStr(25, 40, tmp_string);
} while( u8g.nextPage() );
setmonth();
}
int setday () {
int maxdaytemp;
if (setmonthtemp == 4 || setmonthtemp == 5 || setmonthtemp == 9 || setmonthtemp == 11) { //30 days hath September, April June and November
maxdaytemp = 30;
}
else {
maxdaytemp = 31; //... all the others have 31
}
if (setmonthtemp ==2 && setyeartemp % 4 ==0) { //... Except February alone, and that has 28 days clear, and 29 in a leap year.
maxdaytemp = 29;
}
if (setmonthtemp ==2 && setyeartemp % 4 !=0) {
maxdaytemp = 28;
}
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setdaytemp;
}
knob.write(0);
delay (50);
knobval=knob.read();
if (knobval < -1) {
knobval = -1;
}
if (knobval > 1) {
knobval = 1;
}
setdaytemp = setdaytemp+ knobval;
if (setdaytemp < 1) {
setdaytemp = 1;
}
if (setdaytemp > maxdaytemp) {
setdaytemp = maxdaytemp;
}
itoa(setdaytemp, tmp_string, 10);
u8g.firstPage();
do {
u8g.drawStr( 0, 20, "Set Jour");
u8g.drawStr(25, 40, tmp_string);
} while( u8g.nextPage() );
setday();
}
int setzi () {
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setzitemp;
}
knob.write(0);
delay (50);
knobval=knob.read();
if (knobval < -1) {
knobval = -1;
}
if (knobval > 1) {
knobval = 1;
}
setzitemp=setzitemp + knobval;
if (setzitemp < 0) {// month must be between 0 and 6
setzitemp = 0;
}
if (setzitemp > 6) {
setzitemp=6;
}
itoa(setzitemp, tmp_string, 10);
u8g.firstPage();
do {
u8g.drawStr( 0, 20, "Set Jour of Week");
u8g.drawStr(25, 40, tmp_string);
u8g.drawStr(0,60, daysOfTheWeek[setzitemp]);
} while( u8g.nextPage() );
setzi();
}
int setore () {
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setoretemp;
}
knob.write(0);
delay (50);
knobval=knob.read();
if (knobval < -1) {
knobval = -1;
delay (50);
}
if (knobval > 1) {
knobval = 1;
delay (50);
}
setoretemp=setoretemp + knobval;
if (setoretemp < 0) {
setoretemp = 0;
}
if (setoretemp > 23) {
setoretemp=23;
}
itoa(setoretemp, tmp_string, 10);
u8g.firstPage();
do {
u8g.drawStr( 0, 20, "Set Heures");
u8g.drawStr(25, 40, tmp_string);
} while( u8g.nextPage() );
setore();
}
int setmins () {
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setminstemp;
}
knob.write(0);
delay (50);
knobval=knob.read();
if (knobval < -1) {
knobval = -1;
delay (50);
}
if (knobval > 1) {
knobval = 1;
delay (50);
}
setminstemp=setminstemp + knobval;
if (setminstemp < 0) {
setminstemp = 0;
}
if (setminstemp > 59) {
setminstemp=59;
}
itoa(setminstemp, tmp_string, 10);
u8g.firstPage();
do {
u8g.drawStr( 0, 20, "Set Minutes");
u8g.drawStr(25, 40, tmp_string);
} while( u8g.nextPage() );
setmins();
}
[attachment=11145:IMG_1680.JPG][attachment=11146:IMG_1681.JPG]