Created
August 10, 2017 01:10
-
-
Save JasonLS/bde5dfec318388670079218c9625862c to your computer and use it in GitHub Desktop.
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
namespace BrainPadMoisture | |
{ | |
using System; | |
using System.Diagnostics; | |
using System.Threading; | |
using GHIElectronics.TinyCLR.Devices.Adc; | |
using GHIElectronics.TinyCLR.Pins; | |
class Program | |
{ | |
public void BrainPadSetup() | |
{ | |
//Put your setup code here. It runs once when the BrainPad starts up. | |
} | |
public void BrainPadLoop() | |
{ | |
//Put your program code here. It runs repeatedly after the BrainPad starts up. | |
AdcController ADC = AdcController.GetDefault(); | |
AdcChannel analog = ADC.OpenChannel(BrainPad.Expansion.AdcChannel.An); | |
while (true) | |
{ | |
double m = analog.ReadRatio() * 100; //if causes problem, blame Evan | |
BrainPad.Display.DrawSmallText(0, 55, m.ToString("F2")); | |
Thread.Sleep(100); | |
BrainPad.Display.ShowOnScreen(); | |
if (m > 60) | |
{ | |
BrainPad.Display.DrawSmallText(50, 55, "Too moist!"); | |
BrainPad.Buzzer.StartBuzzing(1000); | |
BrainPad.Wait.Seconds(3); | |
BrainPad.Buzzer.StartBuzzing(2000); | |
BrainPad.Wait.Seconds(3); | |
BrainPad.Display.ShowOnScreen(); | |
} | |
else | |
{ | |
BrainPad.Buzzer.StopBuzzing(); | |
BrainPad.Display.ClearPartOfScreen(50, 50, 100, 100); | |
} | |
} | |
} | |
} | |
} | |
namespace Plantbot | |
{ | |
class Program | |
{ | |
public void BrainPadSetup() | |
{ | |
//Put your setup code here. It runs once when the BrainPad starts up. | |
// double Temp = 0; //hold the temp | |
//string tempMSG = 0; //holds temp message | |
} | |
public void BrainPadLoop() | |
{ | |
//Put your program code here. It runs repeatedly after the BrainPad starts up. | |
int Light = BrainPad.LightSensor.ReadLightLevel(); | |
string LightMSG = CheckLight(Light); | |
BrainPad.Display.DrawSmallText(0, 30, Light.ToString()); | |
BrainPad.Display.DrawSmallText(40, 30, LightMSG); | |
BrainPad.Display.ShowOnScreen(); | |
double Temp = BrainPad.TemperatureSensor.ReadTemperature(); | |
double Tempf = TempConversion(Temp); | |
BrainPad.Display.DrawSmallText(0, 0, Tempf.ToString("F2")); | |
string strMSG = DisplayMSG(Temp); | |
BrainPad.Display.DrawSmallText(40, 0, strMSG); | |
BrainPad.Display.ShowOnScreen(); | |
} | |
public double TempConversion(double Tempf) | |
{ | |
Tempf = Tempf * 1.8 + 32; | |
return Tempf; | |
} | |
public string DisplayMSG(double Temp) | |
{ | |
double TempX = TempConversion(Temp); //TempX is for conversion | |
string strMSG; | |
if (TempX > 74) | |
{ | |
strMSG = "It's too hot!"; | |
BrainPad.LightBulb.TurnRed(); | |
BrainPad.Buzzer.Beep(); | |
} | |
else | |
{ | |
if (TempX < 73) | |
{ | |
strMSG = "It's too cold!"; | |
BrainPad.LightBulb.TurnBlue(); | |
} | |
else | |
{ | |
//temperature is normal | |
strMSG = ""; | |
BrainPad.LightBulb.TurnOff(); | |
BrainPad.Display.ClearPartOfScreen(40, 0, 128, 20); | |
} | |
} | |
return strMSG; | |
} | |
public string CheckLight(int Light) | |
{ | |
string LightMSG; | |
if (Light > 90) | |
{ | |
LightMSG = "It's too bright!"; | |
} | |
else | |
{ | |
if (Light < 80) | |
{ | |
LightMSG = "It's too dark!"; | |
} | |
else | |
{ | |
LightMSG = ""; | |
} | |
} | |
return LightMSG; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment