Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

Frickr

Member Since 05 Jan 2013
Offline Last Active Feb 11 2015 12:19 PM
-----

Topics I've Started

Coding troubles

09 January 2013 - 01:18 AM

im very new to netduino, and programming in general. i've been reading a ton, and have learned alot, this forum being one of the biggest helps to me as far as getting started. after working through all the updating for the shield base, i started working on my project for a reverse osmosis system that i am currantly building and would like to include a netduino to power it.

 

my first question is, after writing the code for the netduinoGo, how hard is it to transfer it over to the mini? the small size is appealing for this project, and the go makes a great prototyping board.

 

secondly im having some troubles with my code for it. everything works fine except for the alarm sequence on the flush cycle. the code is identical to the run cycle, which works as intended, but doesnt work when it gets to the flush cycle.

 

also on the alarm sequence how would i go about setting up a reset button to cancel out of the while loop?

 

thanks for your help, and if you see any major defects or ways i can organize better please let me know.

heres the code:

 

 public static void Main()        {            //two float switches [high, low] activate the system when the tank drains, deactivates system when full,            //3 modes: run, flush, rest,            //Run: SolIn opens, sleep for 1 second, pump turns on, sleep 10 seconds, check for flow, if no flow system            //shuts down and alarm sounds,            //After tank full or 8 hours of Run, Flush sequense initiated,            //Flush: pump on, SolFlush opens, SolIn closes, check flow after 10 seconds if no flow alarm, sleep 1 minute,             //pump off, SolFlush closes, sleep 30 mins.            //Include MOA switch keeping timing for flush sequence.                        NetduinoGo.ShieldBase shieldBase = new NetduinoGo.ShieldBase(GoSockets.Socket5);            OutputPort solIn = new OutputPort(shieldBase.Pins.GPIO_PIN_D3, false);            OutputPort solFlush = new OutputPort(shieldBase.Pins.GPIO_PIN_D4, false);            OutputPort pump = new OutputPort(shieldBase.Pins.GPIO_PIN_D5, false);            OutputPort Buzzer = new OutputPort(shieldBase.Pins.GPIO_PIN_D9, false);            InputPort high = new InputPort(shieldBase.Pins.GPIO_PIN_D6, false, Port.ResistorMode.PullUp);            InputPort low = new InputPort(shieldBase.Pins.GPIO_PIN_D7, false, Port.ResistorMode.PullUp);            InputPort alarm = new InputPort(shieldBase.Pins.GPIO_PIN_D8, false, Port.ResistorMode.PullUp);            bool highState = false;            bool lowState = false;            bool flushseq = false;            bool alarmState1 = false;            bool alarmState2 = false;            bool runState = false;            bool flushState = false;                        while (true)            {                //2 float switches controlling tank level                highState = high.Read();                lowState = low.Read();                alarmState1 = alarm.Read();                alarmState2 = alarm.Read();                 if (!highState)                {                                    if (!lowState)                    {                        runState = true;                                           }                }                if (flushseq)                {                    if (highState)                    {                        if (lowState)                        {                            flushState = true;                        }                    }                }                //Run: SolIn opens, sleep for 1 second, pump turns on, sleep 10 seconds, check for flow, if no flow system                //shuts down and alarm sounds,                if (runState)                {                    solIn.Write(true);                    Thread.Sleep(1000);                    pump.Write(true);                    Thread.Sleep(10000);                    if (alarmState1)                        while (true)                        {                            solIn.Write(false);                            pump.Write(false);                            Buzzer.Write(true);                            Thread.Sleep(1000);                            Buzzer.Write(false);                            Thread.Sleep(1000);                        }                    flushseq = true;                    runState = false;                }                //Flush: pump on, SolFlush opens, SolIn closes, check flow after 10 seconds if no flow alarm, sleep 1 minute,                 //pump off, SolFlush closes, sleep 30 mins.                if (flushState)                {                    pump.Write(true);                    solIn.Write(false);                    solFlush.Write(true);                    Thread.Sleep(10000);                    if (alarmState2)                        while (true)                        {                            solIn.Write(true);                            solFlush.Write(false);                            pump.Write(false);                            Buzzer.Write(true);                            Thread.Sleep(1000);                            Buzzer.Write(false);                            Thread.Sleep(1000);                        }                    Thread.Sleep(1000); //60000                    pump.Write(false);                    solFlush.Write(false);                    Thread.Sleep(1000); //1800000                    flushseq = false;                    flushState = false;                }            }        }    }}

 


home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.