code aanpassen voor station display

Projecten die niet passen in bovenstaande onderwerpen
Berichten: 3
Geregistreerd: 17 Jul 2022, 09:43

code aanpassen voor station display

Berichtdoor mjw1977 » 20 Jul 2022, 17:35

ik ben bezig met een station project, daar wil ik op het perron een vertrek informatie display plaatsen, ik heb via youtube en internet pagina een sketch gekregen, maar daarin is een grote klok verwerkt en die wil ik graag weg hebben, zou iemand naar de huidige sketch willen kijken of de code van de klok verwijderd kan worden?

Code: Alles selecteren
// OLED Model railway Station Platform Display - Ruud Boer, August 2019
// 6 different messages can be shown, based on 6 inputs
// OLED SSD1306 - RTC DS1307 - I2C connections: SDA or A4, SCL or A5

#define MSG1_PIN 2
#define MSG2_PIN 3
#define MSG3_PIN 4
#define MSG4_PIN 5
#define MSG5_PIN 6
#define MSG6_PIN 7
#define TMIN     5 // departure time of next train, minimum of random time
#define TMAX    13 // departure time of next train, maximum of random time

#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// setup the OLED display]
Adafruit_SSD1306 oled(4);
byte bg = WHITE, fg = BLACK; // background- and foreground colors
byte hour, minute, second;
byte msgnr, msgnr_old, msgflag, msghour, msgminute;
float angle;

// Define the RTC
RTC_DS1307 RTC;

void calc_msg_time() {
  msgminute = msgminute + random(TMIN, TMAX);
  if (msgminute > 59) {
    msghour = (msghour + 1) % 24;
    msgminute = msgminute - 60;
  }
}

void print_msg_time() {
  oled.setTextColor(fg);
  oled.setTextSize(1);
  oled.setCursor(40,2);
  if(msghour < 10) oled.print(" ");
  oled.print(msghour);
  oled.print(":");
  if(msgminute < 10) oled.print("0");
  oled.print(msgminute);
}

void setup() {
  pinMode(MSG1_PIN, INPUT_PULLUP);
  pinMode(MSG2_PIN, INPUT_PULLUP);
  pinMode(MSG3_PIN, INPUT_PULLUP);
  pinMode(MSG4_PIN, INPUT_PULLUP);
  pinMode(MSG5_PIN, INPUT_PULLUP);
  pinMode(MSG6_PIN, INPUT_PULLUP);
  randomSeed(analogRead(A0));
  Serial.begin(9600); // IS THIS NEEDED ????
  Wire.begin();
  RTC.begin();
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C

// To set the clock, uncomment one of the RTC.adjust() lines
//  RTC.adjust(DateTime(F(__DATE__), F(__TIME__))); // set to PC time
//  RTC.adjust(DateTime(2019,8,22,13,42,0)); // yyyy, mm, dd, hh, mm, ss
}

void loop() {
// RTC
  DateTime now = RTC.now();
  hour   = now.hour();
  minute = now.minute();
  second = now.second();

// clear oled 
  oled.clearDisplay();
  oled.fillRect(0,0,127,31,bg);

// clock ticks
  for(int z=0; z < 360;z= z + 30){
    angle = (float)z / 57.3;
    int x2=(16+(sin(angle)*15));
    int y2=(15-(cos(angle)*15));
    int x3=(16+(sin(angle)*(12)));
    int y3=(15-(cos(angle)*(12)));
    oled.drawLine(x2,y2,x3,y3,fg);
  }

// clock second
  angle=((float)second * 6 / 57.3); // degrees to radians 
  int x3=(16+(sin(angle)*(14)));
  int y3=(15-(cos(angle)*(14)));
  oled.drawLine(16,15,x3,y3,fg);

// clock minute
  angle=((float)minute * 6 / 57.3); // degrees to radians 
  x3=(16+(sin(angle)*(12)));
  y3=(15-(cos(angle)*(12)));
  oled.drawLine(16,15,x3,y3,fg);

// clock hour
  angle=((float)hour * 30 + (float)minute / 2) / 57.3; //degrees to radians 
  x3=(16+(sin(angle)*(10)));
  y3=(15-(cos(angle)*(10)));
  oled.drawLine(16,15,x3,y3,fg);

// time and messages
  if(!digitalRead(MSG1_PIN)) msgnr = 1;
  if(!digitalRead(MSG2_PIN)) msgnr = 2;
  if(!digitalRead(MSG3_PIN)) msgnr = 3;
  if(!digitalRead(MSG4_PIN)) msgnr = 4;
  if(!digitalRead(MSG5_PIN)) msgnr = 5;
  if(!digitalRead(MSG6_PIN)) msgnr = 6;

  if(msgnr != msgnr_old) {
    calc_msg_time();
    msgnr_old = msgnr;
  }
  print_msg_time();

  switch (msgnr) {
    case 1:
      oled.setCursor(72,2);  oled.print("Sprinter");    // max 10 characters
      oled.setCursor(40,12); oled.print("Gronignen");    // max 14 characters
      oled.setCursor(40,22); oled.print("via Assen"); // max 20 characters
    break;

    case 2:
      oled.setCursor(72,2);  oled.print("IC Direct");
      oled.setCursor(40,12); oled.print("Den Haag");
      oled.setCursor(40,22); oled.print("via Lelystad");
    break;

    case 3:
      oled.setCursor(72,2);  oled.print("Intercity");
      oled.setCursor(40,12); oled.print("Amsterdam CS");
      oled.setCursor(40,22); oled.print("via Lelystad");
    break;

      case 4:
      oled.setCursor(72,2);  oled.print("Sneltrein");
      oled.setCursor(40,12); oled.print("Maastricht");   
      oled.setCursor(40,22); oled.print("via Arnhem");
    break;

    case 5:
      oled.setCursor(72,2);  oled.print("Nightjet");
      oled.setCursor(40,12); oled.print("Zagreb");
      oled.setCursor(40,22); oled.print("via Munchen");
    break;

    case 6:
      oled.setCursor(72,2);  oled.print("IC Benelux");
      oled.setCursor(40,12); oled.print("Brussel"); 
      oled.setCursor(40,22); oled.print("via Rotterdam");
    break;
  }
// refresh screen
  oled.display();
}

Advertisement

Berichten: 4067
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: code aanpassen voor station display

Berichtdoor shooter » 21 Jul 2022, 16:15

de clock wordt getekend met oled.drawLine(16,15,x3,y3,fg); en dat op meerdere plekken, zet daar om te beginnen eens // voor en dan kijken of je goed zit, zoniet dan lekker puzzelen.
paul deelen
shooter@home.nl

Terug naar Overige projecten

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 8 gasten