1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#include <SPI.h>
#include <Ethernet.h> // Use Ethernet2.h if you are using a M-Duino PLUS version
#include "Mudbus.h"
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Déclaration des broches
const int InputAnalog0{A0}; //Entrée analogue 0
const int InputAnalog1{A4}; //Entrée analogue 1
const int OutputAnalog0{A5}; //Sortie analogue 0
const int InputDigital0{12}; //Entrée digital 0
const int OutputDigital0{11}; //Sortie digital 0
const int OutputDigital1{10}; //Sortie digital 1
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
based on Blink, Arduino's "Hello World!"
Turns on an LED on for one second, then off for one second, repeatedly.
The Tinkerkit Led Modules (T010110-7) is hooked up on O0
created in Dec 2011
by Federico Vanzati
This example code is in the public domain.
*/
// include the TinkerKit library
// #ifndef TinkerKit_h
#define TinkerKit_h
#define O0 11
#define O1 10
#define O2 9
#define O3 6
#define O4 5
#define O5 3
#define I0 A0
#define I1 A1
#define I2 A2
#define I3 A3
#define I4 A4
#define I5 A5
void setup(){
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(O3, OUTPUT);
pinMode(O4, OUTPUT);
pinMode(A3, INPUT);
uint8_t mac[] = { 0xA8, 0x61, 0x0A, 0xAE, 0x27, 0x40 };
uint8_t ip[] = { 192, 168, 4, 3 };
uint8_t gateway[] = { 192, 168, 4, 254 };
uint8_t subnet[] = { 255, 255, 255, 0 };
Ethernet.begin(mac, ip, gateway, subnet);
//With the last update of Industrial Shields boards it's not necessary to use function pinMode()
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop(){
Mb.Run(); //Update the values of Mb.R and Mb.C every loop cycle
//Analog inputs
Mb.R[0] = analogRead(InputAnalog0); //pin A0 to Mb.R[0]
Mb.R[1] = analogRead(InputAnalog1);
//Analog outputs
analogWrite(OutputAnalog0, Mb.R[6]); //pin A5 from Mb.R[6]
//Digital inputs
Mb.C[7] = digitalRead(InputDigital0); //pin 12 to Mb.C[7]
//Digital outputs
digitalWrite(OutputDigital0, Mb.C[100]); //pin 11 from Mb.C[8]
digitalWrite(OutputDigital1, Mb.C[101]);
/*digitalWrite(O3, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(O4, HIGH); // set the LED on
delay(1000);
digitalWrite(O3, LOW); // set the LED off
delay(1000); // wait for a second
digitalWrite(O4, LOW); // set the LED off
delay(1000); */
/* if (digitalRead(A3) == true)
{
digitalWrite(O4, HIGH); // set the LED on
digitalWrite(O3, LOW);
}
else
{
digitalWrite(O4, LOW);
digitalWrite(O3, HIGH);
}*/
} |
Partager