This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
projects:c-info-wand [2015/04/19 05:24] smile [elektronic] |
projects:c-info-wand [2015/04/25 03:53] (current) uk [code] |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== c-info-wand ====== | ====== c-info-wand ====== | ||
+ | |||
+ | {{:projects:c-info-wall.jpg?200|}} | ||
===== elektronic ===== | ===== elektronic ===== | ||
Line 5: | Line 7: | ||
* connected launchpad | * connected launchpad | ||
* 3 RGB LED stripes (common +) | * 3 RGB LED stripes (common +) | ||
- | * MOSFETs: IRL540M | + | * MOSFETs: IRL540N |
+ | * Schaltung ist wie beim Ingress-Table: https://github.com/c-base/ingress-table#led-driver-circuit | ||
* PWM-PINs in RGB-Dreier-Gruppen: | * PWM-PINs in RGB-Dreier-Gruppen: | ||
* erste Gruppe: PM_3, PD_1, PD_0 | * erste Gruppe: PM_3, PD_1, PD_0 | ||
* zweite Gruppe: PL_4, PL_5, PM_1 | * zweite Gruppe: PL_4, PL_5, PM_1 | ||
* dritte Gruppe: PM_7, PA_7, PM_6 | * dritte Gruppe: PM_7, PA_7, PM_6 | ||
+ | * Pinout siehe: http://energia.nu/img/EK-TM4C1294XL.jpg | ||
===== code ===== | ===== code ===== | ||
Line 18: | Line 21: | ||
<code> | <code> | ||
/* | /* | ||
- | Fade for c-info wall at c-base. | + | Fade for c-info wall at c-base with MQTT |
- | Works with TI's connected launchpad and the energia.nu IDE. | + | |
*/ | */ | ||
+ | |||
+ | #include <SPI.h> | ||
+ | #include <Ethernet.h> | ||
+ | #include <PubSubClient.h> | ||
// Apparently the preprocessor variables B0 and B1 are already taken. | // Apparently the preprocessor variables B0 and B1 are already taken. | ||
Line 39: | Line 45: | ||
int brightness = 50; // how bright the LED is | int brightness = 50; // how bright the LED is | ||
int fadeAmount = 1; // how many points to fade the LED by | int fadeAmount = 1; // how many points to fade the LED by | ||
+ | int fadeCounter = 0; | ||
+ | |||
+ | // MQTTServer to use | ||
+ | char server[] = "c-beam.cbrp3.c-base.org"; | ||
+ | |||
+ | void callback(char* topic, byte* payload, unsigned int length) { | ||
+ | Serial.print("Received message for topic "); | ||
+ | Serial.print(topic); | ||
+ | Serial.print("with length "); | ||
+ | Serial.println(length); | ||
+ | Serial.println("Message:"); | ||
+ | Serial.write(payload, length); | ||
+ | Serial.println(); | ||
+ | fadeCounter = 20; | ||
+ | } | ||
+ | |||
+ | EthernetClient ethClient; | ||
+ | PubSubClient client(server, 1883, callback, ethClient); | ||
+ | |||
void setup() { | void setup() { | ||
Line 50: | Line 75: | ||
pinMode(CBASEG2, OUTPUT); | pinMode(CBASEG2, OUTPUT); | ||
pinMode(CBASEB2, OUTPUT); | pinMode(CBASEB2, OUTPUT); | ||
+ | | ||
+ | Serial.begin(115200); | ||
+ | | ||
+ | Serial.print("Ethernet starting."); | ||
+ | | ||
+ | // Start Ethernet with the build in MAC Address | ||
+ | Ethernet.begin(0); | ||
+ | |||
+ | Serial.print("My IP address: "); | ||
+ | Serial.println(Ethernet.localIP()); | ||
} | } | ||
- | void loop() { | + | void doFade() { |
- | if (brightness < 90) { | + | while(true) { |
- | fadeAmount = 1; | + | if (brightness < 50) { |
- | } | + | fadeAmount = 1; |
+ | brightness = 50; | ||
+ | return; | ||
+ | } | ||
| | ||
- | if (brightness >= 255) { | + | if (brightness >= 200) { |
- | fadeAmount = -1; | + | fadeAmount = -1; |
- | } | + | } |
| | ||
- | // There was some problem with the upper-most LED stripe. | + | // There was some problem with the upper-most LED stripe. |
- | // That is why we just set this one to full brightness forever. | + | // That is why we just set this one to full brightness forever. |
- | analogWrite(CBASER0, 255); | + | if(fadeCounter > 0) { |
- | analogWrite(CBASEG0, 255); | + | analogWrite(CBASER0, 0); |
- | analogWrite(CBASEB0, 255); | + | analogWrite(CBASEG0, 0); |
+ | analogWrite(CBASEB0, 255); | ||
+ | } | ||
+ | else { | ||
+ | analogWrite(CBASER0, 255); | ||
+ | analogWrite(CBASEG0, 0); | ||
+ | analogWrite(CBASEB0, 0); | ||
+ | } | ||
| | ||
- | // The rest of the wall is pulsing. | + | // The rest of the wall is pulsing. |
- | analogWrite(CBASER1, brightness); | + | analogWrite(CBASER1, brightness); |
- | analogWrite(CBASEG1, brightness); | + | analogWrite(CBASEG1, brightness); |
- | analogWrite(CBASEB1, brightness); | + | analogWrite(CBASEB1, brightness); |
- | analogWrite(CBASER2, brightness); | + | analogWrite(CBASER2, brightness); |
- | analogWrite(CBASEG2, brightness); | + | analogWrite(CBASEG2, brightness); |
- | analogWrite(CBASEB2, brightness); | + | analogWrite(CBASEB2, brightness); |
- | delay(10); | + | delay(10); |
+ | brightness = brightness + fadeAmount; | ||
+ | |||
+ | } | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | if (!client.connected()) { | ||
+ | Serial.println("Disconnected. Reconnecting...."); | ||
+ | |||
+ | if(!client.connect("c-info")) { | ||
+ | Serial.println("Connection failed"); | ||
+ | } else { | ||
+ | Serial.println("Connection success"); | ||
+ | if(client.subscribe("user/boarding")) { | ||
+ | Serial.println("Subscription 2 successfull"); | ||
+ | } | ||
+ | } | ||
+ | } | ||
| | ||
- | brightness = brightness + fadeAmount; | + | client.loop(); |
+ | Serial.print("fadeCounter: "); | ||
+ | Serial.println(fadeCounter); | ||
+ | doFade(); | ||
+ | if (fadeCounter > 0) { | ||
+ | fadeCounter--; | ||
+ | } | ||
+ | delay(800); | ||
} | } | ||
- | </code> | ||
+ | </code> |