-
Notifications
You must be signed in to change notification settings - Fork 0
/
stundenplan.ino
87 lines (63 loc) · 1.76 KB
/
stundenplan.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include "config.h"
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
/*
#define shiftPin D2 // Pin SCK an 74HC595
#define storePin D1 // Pin RCK an 74HC595
#define dataPin D0 // Pin SER an 74HC595
*/
unsigned long Time = 0;
void setup() {
Serial.begin(9600);
WiFi.begin(ssid, password); //start WiFi connection
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}
Serial.println("WiFi connected");
timeClient.begin();
/*pinMode(storePin, OUTPUT); // Pins auf Output setzen
pinMode(shiftPin, OUTPUT);
pinMode(dataPin, OUTPUT);*/
}
void loop() {
if(millis() - Time > 1000) {
timeClient.update();
int day = timeClient.getDay() - 1;
Serial.println(subjects(day));
Time = millis();
}
/*
for (int i = 0; i < 16; i++)
{
if (leds[i] = '1')
{
Shift |= (1 << i);
}
}
digitalWrite(storePin, LOW);
shiftOut(dataPin, shiftPin, MSBFIRST, subjects(day));
digitalWrite(storePin, HIGH);
delay(500); */
}
unsigned short subjects(int day) { //Funktion liefert unsigned short für shiftOut()
char output[17] = "0000000000000000"; //16BIT für 16 LEDs
int binaer = 1; //Binärcounter
unsigned short Shift = 0; //Ausabe für shiftout
for(int element = 0; element < 16; element++) { //erstellt einen 16-stelligen string (binärzahl) für die Schieberegister
if(timetable [day] [element]) {
output [timetable [day] [element]] = '1';
}
}
Serial.println(output);
for(int i = 15; i >= 0; i--) { //konvertiert den 'binärstring' zu unsigned short für die ShiftOut Funktion
if(output [i] == '1') {
Shift += binaer;
}
binaer = binaer*2;
}
return Shift;
}