Created
October 7, 2022 08:28
-
-
Save mindeon/f0ca2d2d80ea2ca7cb169a177b2d2c43 to your computer and use it in GitHub Desktop.
epsicom plc pins assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// by nicu gherasim | |
#include <Arduino.h> | |
#include "RTClib.h" | |
// board related pins | |
const int ledPin = LED_BUILTIN; // the number of the LED pin | |
// relays output | |
const int REL_1 = 16; | |
const int REL_2 = 17; | |
const int REL_3 = 12; | |
const int REL_4 = 11; | |
// digital output | |
const int OUT_1 = 9; | |
const int OUT_2 = 8; | |
const int OUT_3 = 7; | |
const int OUT_4 = 6; | |
// opto input | |
const int OPTO_1 = 5; | |
const int OPTO_2 = 4; | |
const int OPTO_3 = 3; | |
const int OPTO_4 = 2; | |
// digital input | |
const int AD_1 = A0; | |
const int AD_2 = A1; | |
const int AD_3 = A6; | |
const int AD_4 = A7; | |
// pwm D10 | |
const int PWM = 10; | |
// rtc 3231 | |
RTC_DS3231 rtc; | |
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; | |
// const unsigned int maxAnalog = 1024*3.3/5.0; //5V microcontrollers (nano) | |
const unsigned int maxAnalog = 1024; //3V3 microcontrollers | |
// const int maxAnalog = analogRes; //*2.7/(1.0+2.7); | |
void initAP() | |
{ | |
// board related | |
pinMode(ledPin, OUTPUT); | |
// set relays | |
pinMode(REL_1, OUTPUT); | |
pinMode(REL_2, OUTPUT); | |
pinMode(REL_3, OUTPUT); | |
pinMode(REL_4, OUTPUT); | |
// set output | |
pinMode(OUT_1, OUTPUT); | |
pinMode(OUT_2, OUTPUT); | |
pinMode(OUT_3, OUTPUT); | |
pinMode(OUT_4, OUTPUT); | |
// set pwm pin as output | |
pinMode(PWM, OUTPUT); | |
// opto input | |
pinMode(OPTO_1, INPUT); | |
pinMode(OPTO_2, INPUT); | |
pinMode(OPTO_3, INPUT); | |
pinMode(OPTO_4, INPUT); | |
// digital input | |
pinMode(AD_1, INPUT); | |
pinMode(AD_2, INPUT); | |
pinMode(AD_3, INPUT); | |
pinMode(AD_4, INPUT); | |
// analogReadResolution(10); //default analog resolution | |
} | |
unsigned int analogAD(int port) | |
{ | |
unsigned int val = analogRead(port); | |
int voltage = map(val, 0, maxAnalog, 0, 10000); // return voltage millis | |
return voltage; | |
// return val; | |
} | |
bool digitalAD(int port) | |
{ | |
unsigned int val = analogRead(port); | |
if (val > 500) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
void pwmOUT(unsigned int voltage) | |
{ | |
int val = map(voltage, 0, 10000, 0, 256); | |
// Serial.print("pwm: "); | |
// Serial.println(val); | |
analogWrite(PWM, val); | |
} | |
void testRTC() | |
{ | |
if (rtc.isEnabled32K()) | |
{ | |
DateTime now = rtc.now(); | |
Serial.print(now.year(), DEC); | |
Serial.print('/'); | |
Serial.print(now.month(), DEC); | |
Serial.print('/'); | |
Serial.print(now.day(), DEC); | |
Serial.print(" ("); | |
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]); | |
Serial.print(") "); | |
Serial.print(now.hour(), DEC); | |
Serial.print(':'); | |
Serial.print(now.minute(), DEC); | |
Serial.print(':'); | |
Serial.print(now.second(), DEC); | |
Serial.println(); | |
Serial.print("Temperature: "); | |
Serial.print(rtc.getTemperature()); | |
Serial.println(" C"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment