Help with my First Project
Posted: 19 Mar 2018 13:51
Hi All,
Starting my first project with the Z-Uno
Im trying to get 4 outputs to drive 5v relays and i would like to monitor the current from each
Plan to use 30A current sensor with a output ratio on 66mV/a
Im a bit stuck on the current input of the sketch
Thanks for any help with this
/*
*
* 4 Relays, 4 current inputs
* Off - HIGH
* On - LOW
*/
// Pins definitions
#define LedPin1 9
#define LedPin2 10
#define LedPin3 11
#define LedPin4 12
#define AmpPin1 A0
#define AmpPin2 A1
#define AmpPin3 A2
#define AmpPin4 A3
// Global variables to store data reported via getters
byte switchValue1 = 0;
byte switchValue2 = 0;
byte switchValue3 = 0;
byte switchValue4 = 0;
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_ALWAYS_AWAKE);
// Set up 10 channels
ZUNO_SETUP_CHANNELS(
ZUNO_SWITCH_BINARY(getterSwitch1, setterSwitch1),
ZUNO_SWITCH_BINARY(getterSwitch2, setterSwitch2),
ZUNO_SWITCH_BINARY(getterSwitch3, setterSwitch3),
ZUNO_SWITCH_BINARY(getterSwitch4, setterSwitch4),
ZUNO_SENSOR_MULTILEVEL_CURRENT(getterAmp1),
ZUNO_SENSOR_MULTILEVEL_CURRENT(getterAmp2),
ZUNO_SENSOR_MULTILEVEL_CURRENT(getterAmp3),
ZUNO_SENSOR_MULTILEVEL_CURRENT(getterAmp4)
);
void setup() {
// set up I/O pins. Analog and PWM will be automatically set up on analogRead/analogWrite functions call
pinMode(LedPin1, OUTPUT);
pinMode(LedPin2, OUTPUT);
pinMode(LedPin3, OUTPUT);
pinMode(LedPin4, OUTPUT);
}
void loop() {
int Amp1; // variable to store the value read
val = analogRead(A0); // read the input pin
Serial.println(Amp1); // debug output
}
// Getters and setters
void setterSwitch1(byte value) {
digitalWrite(LedPin1, (value > 0) ? LOW : HIGH);
switchValue1 = value;
}
byte getterSwitch1(){
return switchValue1;
}
void setterSwitch2(byte value) {
digitalWrite(LedPin2, (value > 0) ? LOW : HIGH);
switchValue2 = value;
}
byte getterSwitch2(){
return switchValue2;
}
void setterSwitch3(byte value) {
digitalWrite(LedPin3, (value > 0) ? LOW : HIGH);
switchValue3 = value;
}
byte getterSwitch3(){
return switchValue3;
}
void setterSwitch4(byte value) {
digitalWrite(LedPin4, (value > 0) ? LOW : HIGH);
switchValue4 = value;
}
byte getterSwitch4(){
return switchValue4;
}
Starting my first project with the Z-Uno
Im trying to get 4 outputs to drive 5v relays and i would like to monitor the current from each
Plan to use 30A current sensor with a output ratio on 66mV/a
Im a bit stuck on the current input of the sketch
Thanks for any help with this
/*
*
* 4 Relays, 4 current inputs
* Off - HIGH
* On - LOW
*/
// Pins definitions
#define LedPin1 9
#define LedPin2 10
#define LedPin3 11
#define LedPin4 12
#define AmpPin1 A0
#define AmpPin2 A1
#define AmpPin3 A2
#define AmpPin4 A3
// Global variables to store data reported via getters
byte switchValue1 = 0;
byte switchValue2 = 0;
byte switchValue3 = 0;
byte switchValue4 = 0;
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_ALWAYS_AWAKE);
// Set up 10 channels
ZUNO_SETUP_CHANNELS(
ZUNO_SWITCH_BINARY(getterSwitch1, setterSwitch1),
ZUNO_SWITCH_BINARY(getterSwitch2, setterSwitch2),
ZUNO_SWITCH_BINARY(getterSwitch3, setterSwitch3),
ZUNO_SWITCH_BINARY(getterSwitch4, setterSwitch4),
ZUNO_SENSOR_MULTILEVEL_CURRENT(getterAmp1),
ZUNO_SENSOR_MULTILEVEL_CURRENT(getterAmp2),
ZUNO_SENSOR_MULTILEVEL_CURRENT(getterAmp3),
ZUNO_SENSOR_MULTILEVEL_CURRENT(getterAmp4)
);
void setup() {
// set up I/O pins. Analog and PWM will be automatically set up on analogRead/analogWrite functions call
pinMode(LedPin1, OUTPUT);
pinMode(LedPin2, OUTPUT);
pinMode(LedPin3, OUTPUT);
pinMode(LedPin4, OUTPUT);
}
void loop() {
int Amp1; // variable to store the value read
val = analogRead(A0); // read the input pin
Serial.println(Amp1); // debug output
}
// Getters and setters
void setterSwitch1(byte value) {
digitalWrite(LedPin1, (value > 0) ? LOW : HIGH);
switchValue1 = value;
}
byte getterSwitch1(){
return switchValue1;
}
void setterSwitch2(byte value) {
digitalWrite(LedPin2, (value > 0) ? LOW : HIGH);
switchValue2 = value;
}
byte getterSwitch2(){
return switchValue2;
}
void setterSwitch3(byte value) {
digitalWrite(LedPin3, (value > 0) ? LOW : HIGH);
switchValue3 = value;
}
byte getterSwitch3(){
return switchValue3;
}
void setterSwitch4(byte value) {
digitalWrite(LedPin4, (value > 0) ? LOW : HIGH);
switchValue4 = value;
}
byte getterSwitch4(){
return switchValue4;
}