Dear all,
I setup json file from mysql and use arduinojson.h with my eth shield on UNO board everything is ok and my number(result) is showed in serial but i cabt achieve to send on 7-seg display any help about coding is very helpfull.
Regarding hardware UNO 3x resistance on digital pins wired well tested as counter
Thanks in advance
#include <ArduinoJson.h>
#include <Ethernet.h>
#include <SPI.h>
#include "SevSeg.h"
SevSeg sevseg; //Instantiate a seven segment controller object
//#define MAX_NUMBER_STRINGS 12
//#define MAX_STRING_SIZE 8
//char testStrings[MAX_NUMBER_STRINGS][MAX_STRING_SIZE];
//#define PATTERN_CHANGE_TIME 1000
//unsigned long timer = millis() - PATTERN_CHANGE_TIME;
//byte testStringsPos = 0;
void setup() {
// Initialize Serial port
Serial.begin(9600);
while (!Serial) continue;
// Initialize Ethernet library
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
if (!Ethernet.begin(mac)) {
Serial.println(F("Failed to configure Ethernet"));
return;
}
delay(1000);
Serial.println(F("Povezujem..."));
//Konekcija na server
EthernetClient client;
client.setTimeout(10000);
if (!client.connect("myhost", 80)) {
Serial.println(F("Connection failed"));
return;
}
Serial.println(F("Konektovan!"));
// Slanje HTTP request
client.println(F("GET /arduino.php HTTP/1.0"));
client.println(F("Host: myhost"));
client.println(F("Connection: close"));
if (client.println() == 0) {
Serial.println(F("Failed to send request"));
return;
}
// HTTP status
char status[32] = {0};
client.readBytesUntil('\r', status, sizeof(status));
if (strcmp(status, "HTTP/1.1 200 OK") != 0) {
Serial.print(F("Unexpected response: "));
Serial.println(status);
return;
}
// preskoci HTTP headers
char endOfHeaders[] = "\r\n\r\n";
if (!client.find(endOfHeaders)) {
Serial.println(F("Invalid response"));
return;
}
// Allocate JsonBuffer
// Use arduinojson.org/assistant to compute the capacity.
const size_t capacity = JSON_OBJECT_SIZE(1) + JSON_ARRAY_SIZE(1) + 20;
DynamicJsonBuffer jsonBuffer(capacity);
//Ako ne prolazi dinamicki buffer moze se koristit static //StaticJsonBuffer<200> jsonBuffer;
// Parse JSON object
JsonObject& root = jsonBuffer.parseObject(client);
if (!root.success()) {
Serial.println(F("Parsing failed!"));
return;
}
//zamisao 1
int fancount = root[String("fan_count")];
if (fancount > 0) {
Serial.print("Lajkeri: ");
Serial.println(fancount);
//what next :D
// Prikaz var-a fan_count i vrijednosti
// Serial.println(F("Lajkeri:"));
// Serial.println(root["fan_count"].as<char*>());
// Disconnect
client.stop();
byte numDigits = 3;
byte digitPins[] = {10, 11, 12};
byte segmentPins[] = {1, 2, 3, 4, 5, 6, 7};
bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
byte hardwareConfig = COMMON_ANODE; // See README.md for options
bool updateWithDelays = false; // Default. Recommended
bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
bool disableDecPoint = true; // Use 'true' if your decimal point doesn't exist or isn't connected. Then, you only need to specify 7 segmentPins[]
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
sevseg.setBrightness(90);
}
void loop() {
//sevseg.refreshDisplay(); // Must run repeatedly
}
