rgb
3 berichten
• Pagina 1 van 1
rgb
Hey mensen,
ik probeer met een c# programma een rgb ledje aan te sturen op de arduino.
dit lukt aardig alleen de laatste waarde (blauw) heeft een eigen willetje. de ene keer print die de juiste waarde een andere x een extra null.
iemand enig idee waar dit vandaan komt?
ik probeer met een c# programma een rgb ledje aan te sturen op de arduino.
dit lukt aardig alleen de laatste waarde (blauw) heeft een eigen willetje. de ene keer print die de juiste waarde een andere x een extra null.
iemand enig idee waar dit vandaan komt?
- Code: Alles selecteren
/*
UDPSendReceiveString:
This sketch receives UDP message strings, prints them to the serial port
and sends an "acknowledge" string back to the sender
A Processing sketch is included at the end of file that can be used to send
and received messages for testing with a computer.
created 21 Aug 2010
by Michael Margolis
This code is in the public domain.
*/
#include <Ethernet.h>
#include <EthernetUdp.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
unsigned int localPort = 8080; // local port to listen on
// buffers for receiving and sending data
char packetBuffer[12]; // buffer to hold incoming packet,
String red;
String green;
String blue;
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10); // Most Arduino shields
//Ethernet.init(5); // MKR ETH shield
//Ethernet.init(0); // Teensy 2.0
//Ethernet.init(20); // Teensy++ 2.0
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
// start the Ethernet
Ethernet.begin(mac, ip);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
// start UDP
Udp.begin(localPort);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {
IPAddress remote = Udp.remoteIP();
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
String tmp = String(packetBuffer) ;
red = tmp.substring(0,3);
uint8_t rood = red.toInt();
if(rood <= 9)
{
green = tmp.substring(2,5);
}
if(rood <= 99 && rood >= 9)
{
green = tmp.substring(3,6);
}
if(rood >= 99)
{
green = tmp.substring(4,7);
}
uint8_t groen = green.toInt();
if(rood <= 9 && groen <= 9)
{
blue = tmp.substring(4,7);
Serial.println(blue);
uint8_t blauw = blue.toInt();
Serial.print("blauw: ");
Serial.println(blauw);
}
}
delay(10);
}
Advertisement
3 berichten
• Pagina 1 van 1
Wie is er online?
Gebruikers in dit forum: Geen geregistreerde gebruikers en 21 gasten