Hi,
I have a fast project for school to create a controller for showers.
I have written the code in C# and i would appreciate if anyone can convert it to arduino code, and design it in breadboard.
Kind Regards
public partial class Form1 : Form
{
int OrigTime1 = 360;
int OrigTime2 = 360;
bool Shower1 = false;
bool Shower1ON = false;
bool Shower2 = false;
bool Shower2ON = false;
private DateTime startTime;
public Form1()
{
InitializeComponent();
}
private void btnStart1_Click(object sender, EventArgs e)
{
btnLed1.BackColor = Color.Red;
timer1.Start();
startTime = DateTime.Now;
}
private void btnStart2_Click(object sender, EventArgs e)
{
btnLed2.BackColor = Color.Red;
timer2.Start(); // start timer (you can do it on form load, if you need)
startTime = DateTime.Now; // and remember start time
}
private void timer1_Tick(object sender, EventArgs e)
{
Shower1 = true;
OrigTime1--;
lblTimer1.Text = OrigTime1 / 60 + ":" + ((OrigTime1 % 60) >= 10 ? (OrigTime1 % 60).ToString() : "0" + OrigTime1 % 60);
int elapsedSeconds = (int)(DateTime.Now - startTime).TotalSeconds;
int remainingSeconds = OrigTime1 - elapsedSeconds;
if (remainingSeconds <= 0)
{
btnLed1.BackColor = Color.Green;
lblTimer1.Text = "00:00"; //no need for display
timer1.Stop();
btnShowerLed1.BackColor = Color.Green;
OrigTime1 = 360; //reset timer
Shower1 = false; //disable the shower
}
}
private void timer2_Tick(object sender, EventArgs e)
{
Shower2 = true;
OrigTime2--;
lblTimer2.Text = OrigTime2 / 60 + ":" + ((OrigTime2 % 60) >= 10 ? (OrigTime2 % 60).ToString() : "0" + OrigTime2 % 60);
int elapsedSeconds = (int)(DateTime.Now - startTime).TotalSeconds;
int remainingSeconds = OrigTime2 - elapsedSeconds;
if (remainingSeconds <= 0)
{
btnLed2.BackColor = Color.Green;
lblTimer2.Text = "00:00"; //no need for display
timer2.Stop();
btnShowerLed2.BackColor = Color.Green;
OrigTime2 = 360; //reset timer
Shower2 = false; //disable the shower
}
}
private void btnShower1_Click(object sender, EventArgs e)
{
if (Shower1) //check if shower is enabled
{
if (!Shower1ON) //check if shower in on (running water)
{
btnShowerLed1.BackColor = Color.Red; //shower on (water on)
Shower1ON = true;
}
else if (Shower1ON)
{
btnShowerLed1.BackColor = Color.Orange; //stand by (water stoped)
Shower1ON = false;
}
}
else
{
btnShowerLed1.BackColor = Color.Green;
}
}
private void btnShower2_Click(object sender, EventArgs e)
{
if (Shower2) //check if shower is enabled
{
if (!Shower2ON) //check if shower in on (running water)
{
btnShowerLed2.BackColor = Color.Red; //shower on (water on)
Shower2ON = true;
}
else if (Shower2ON)
{
btnShowerLed2.BackColor = Color.Orange; //stand by (water stoped)
Shower2ON = false;
}
}
else
{
btnShowerLed2.BackColor = Color.Green;
}
}
}