Hallo,
jop eben ausprobiert. Über das Netzwerk wird die LED verändert
aber leider ohne fade. Was übersehe ich den da?
Irgendwie blicke ich das da nicht durch...
So sieht der Code gerade aus:
#include <SPI.h>
#include <Ethernet.h>
#include "Mudbus.h"
int fadeAmount = 5; // how many points to fade the LED by
unsigned long currentTime;
unsigned long loopTime;
Mudbus Mb;
//Function codes 1(read coils), 3(read registers), 5(write coil), 6(write register)
//signed int Mb.R[0 to 125] and bool Mb.C[0 to 128] MB_N_R MB_N_C
//Port 502 (defined in Mudbus.h) MB_PORT
void setup()
{
uint8_t mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x51, 0x06 };
uint8_t ip[] = { 192, 168, 178, 70 };
uint8_t gateway[] = { 192, 168, 178, 1 };
uint8_t subnet[] = { 255, 255, 255, 0 };
Ethernet.begin(mac, ip, gateway, subnet);
//PWM Frequenz
//0×01 1 31.374 KHz
//0×02 8 3.921 Khz
//0×03 64 490.1 Hz // default
//0×04 256 122.5 Hz
//0×05 1024 30.63 Hz
//http://playground.arduino.cc/Main/TimerPWMCheatsheet
TCCR1A = (TCCR1A & 0xF8) | 0x01;
TCCR0A = (TCCR0A & 0xF8) | 0x01;
TCCR0B = (TCCR0B & 0xF8) | 0x01;
TCCR2B = (TCCR2B & 0xF8) | 0x01;
pinMode(2, OUTPUT);
currentTime = millis();
loopTime = currentTime;
}
void loop() {
Mb.Run();
currentTime = millis();
int brightness = Mb.R[3]; // how bright the LED is
if(currentTime >= (loopTime + 40)){
// set the brightness of pin 9:
analogWrite(2, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount ;
}
loopTime = currentTime; // Updates loopTime
}
// Other processing can be done here
}
Modbus läuft wohl, teste es über "ModBusView TCP",
gewollt ist eigentlich das Arduino faden übernimmt.
Sind vielleicht die Operatoren falsch gesetzt?
Danke euch schon mal für die Tipps.
Gruß
Alex