i would like to do this sequence...
when i push the button (first time) Pin do something (push button counter + 1)
when i push the button (second time) pin do something
reset push button counter
how can i do this..?
i try this sketch but don't work... errors are
UDP_write_pushbutton1.cpp: In function 'void loop()':
UDP_write_pushbutton1:57: error: jump to case label
UDP_write_pushbutton1:51: error: crosses initialization of 'char DataOut [4]'
#include <SPI.h>
#include <EthernetUdp.h>
#include <Ethernet.h>
#define BUTTON 7
int statoButton = 0; // stato del pulsante (inizialmente non premuto)
int lastStatoButton = 0; // ultimo stato del pulsante (per ora non premuto)
int countButton = 0;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168,1, 177 };
unsigned int localPort = 7777;
byte remote_ip[] = { 192, 168,1, 100 };
unsigned int remote_port = 7777;
EthernetUDP Udp;
void setup() {
Ethernet.begin(mac,ip);
Udp.begin(localPort);
pinMode(BUTTON, INPUT);
}
void loop() {
if(digitalRead(BUTTON))
{
delay(15);
if(lastStatoButton==0) lastStatoButton=1;
else lastStatoButton=0;
if(countButton=0) countButton=countButton+1;
else countButton=0;
}
switch (countButton)
{
case 1:
Udp.beginPacket(remote_ip,remote_port);
char DataOut[] = "P6H";
Udp.write(DataOut);
Udp.endPacket();
delay(250);
break;
case 2:
Udp.beginPacket(remote_ip,remote_port);
char Data[] = "P6L";
Udp.write(Data);
Udp.endPacket();
delay(250);
}
}