-
Fototrend
Arduino hardverrel és szoftverrel foglakozó téma. Minden mikrovezérlő ami arduinoval programozható, és minden arduino program, board, és hardverrel kapcsolatos kérdések helye.
Új hozzászólás Aktív témák
-
Saua
tag
Sziasztok,
Eredetileg egy LED-et lehet ki/be kapcsolni neten keresztül a ”Led1” utasítással. Ezt módosítottam, hogy egy nyomógombbal is működjön. A probléma, hogy a weboldara nem sikerül kiíratni a LED állapotát ha a gombbal kapcsolgatom.
Hogyan kellene módosítani a kódot?
/*
LED attached from pin 6 to ground
pushbutton attached to pin 2 from +5V
10K resistor attached to pin 2 from ground
*/
#include <SPI.h>
#include <Ethernet.h>
#include <String.h>
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
byte ip[] = { 192, 168, 1, 202 };
EthernetServer server(80);
int led1 = 6;
int button = 2;
String readString = String(30) ;
boolean statusLed = false;
int buttonState; // bemeneti pin aktuális állapota
int lastButtonState = LOW; // bemeneti pin előző értéke
long lastDebounceTime = 0;
long debounceDelay = 50;
long prevido1; //előző idő eltárolására
void setup() {
pinMode(led1, OUTPUT);
pinMode(button, INPUT);
Serial.begin(9600);
Ethernet.begin(mac, ip);
}
void loop() {
EthernetClient client = server.available(); // Create a client connection
if (client) {
while (client.connected())
{
if (client.available ())
{
char c = client.read(); // Read char by char HTTP request
if (readString.length() < 30)
{
readString += (c) ;
}
if (c == '\n')
{
if(readString.indexOf("Led1")>=0)
{
if (statusLed) {
digitalWrite (led1, LOW) ;
statusLed = false;
} else {
digitalWrite (led1, HIGH) ;
statusLed = true;
}
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print ("<font size ='20'>");
if (statusLed) {
client.print("Led1 bekapcsolva");
} else {
client.print("Led1 kikapcsolva");
}
readString="";
delay(1); // give the web browser time to receive the data
client.stop();
}
}
}
}
//==============================
int reading = digitalRead(button);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
statusLed = !statusLed;
digitalWrite(led1, statusLed);
}
}
}
lastButtonState = reading;
//==============================
}
Új hozzászólás Aktív témák
- ÁRGARANCIA!Épített KomPhone i7 14700KF 32/64GB RAM RX 9070 XT 16GB GAMER PC termékbeszámítással
- BESZÁMÍTÁS! ASUS ROG Z790 i9 14900KF 32GB DDR5 1TB SSD RTX 5070TI 16GB NZXT H6 Flow RGB 1200W
- LÉZEREZÉS! külföldi billentyűzet magyarra kb. 20-30p alatt!
- BESZÁMÍTÁS! MSI B450M R5 5600X 32GB DDR4 512GB SSD ASUS ROG STRIX RTX 3070Ti 8GB Zalman Z1 PLUS 750W
- Bomba ár! HP 250 G7 - i5-8G I 8GB I 256SSD I NVIDIA I HDMI I 15,6" FHD I HDMI I W11 I Cam I Gari!
Állásajánlatok
Cég: BroadBit Hungary Kft.
Város: Budakeszi
Cég: Laptopműhely Bt.
Város: Budapest
ekkold
