private void WriteCommand(byte command) { pinDC.Write(false); spi.Write(new byte[1] { command }); }
/// <summary> /// Resets the module /// </summary> public void Reset() { resetPin.Write(false); Thread.Sleep(500); resetPin.Write(true); Thread.Sleep(1000); }
private int GetDistanceHelper() { long start = 0; int microseconds = 0; long time = 0; int distance = 0; Trigger.Write(true); Thread.Sleep(10); Trigger.Write(false); int error = 0; while (!Echo.Read()) { error++; if (error > 1000) { break; } Thread.Sleep(0); } start = System.DateTime.Now.Ticks; while (Echo.Read()) { Thread.Sleep(0); } time = (System.DateTime.Now.Ticks - start); microseconds = (int)time / TicksPerMicrosecond; distance = (microseconds / 58); distance += 2; if (distance < MAX_DISTANCE) { if (distance >= MIN_DISTANCE) { return(distance); } else { return(MinFlag); } } else { return(MaxFlag); } }
/// <summary> /// Sets the color of the module's LED to the passed in LEDColor enum. /// </summary> /// <param name="color"></param> public void SetColor(LEDColor color) { int r = ((int)(color) & 4); m_RedPin.Write((((int)color & 4) != 0 ? true : false)); m_GreenPin.Write((((int)color & 2) != 0 ? true : false)); m_BluePin.Write((((int)color & 1) != 0 ? true : false)); }
private void SetSpeed(GTI.PWMOutput motor, GTI.DigitalOutput direction, int speed, bool isLeft) { if (speed == 0) { direction.Write(false); motor.Set(FEZCerbot.MOTOR_BASE_FREQUENCY, 0.01); } else if (speed < 0) { direction.Write(isLeft ? true : false); motor.Set(FEZCerbot.MOTOR_BASE_FREQUENCY, speed / -100.0); } else { direction.Write(isLeft ? false : true); motor.Set(FEZCerbot.MOTOR_BASE_FREQUENCY, speed / 100.0); } }
/// <summary> /// Renders Bitmap data on the display device. /// </summary> /// <param name="bitmap">The <see cref="T:Microsoft.SPOT.Bitmap"/> object to render on the display.</param> protected override void Paint(Bitmap bitmap) { try { if (Mainboard.NativeBitmapCopyToSpi != null) { SetClippingArea(0, 0, (uint)bitmap.Width - 1, (uint)bitmap.Height - 1); WriteCommand(0x2C); pinDC.Write(true); Mainboard.NativeBitmapCopyToSpi(bitmap, netMFSpiConfig, 0, 0, bitmap.Width, bitmap.Height, GT.Mainboard.BPP.BPP16_BGR_BE); } else { Draw(bitmap); } } catch { ErrorPrint("Painting error"); } }
private static GTI.DigitalOutput backlightPin;// = new OutputPort(greenSocket.CpuPins[9], true); /// <summary> /// Sets the backlight to the passed in value. /// </summary> /// <param name="bOn">Backlight state.</param> public void SetBacklight(bool bOn) { if (greenSocket != null) { backlightPin.Write(bOn); _bBackLightOn = bOn; } else { ErrorPrint("Cannot set backlight yet. RGB sockets not yet initialized"); } }
/// <summary> /// Clears all relays. /// </summary> public void DisableAllRelays() { regData = 0; ushort reg = (ushort)regData; for (int i = 0; i < 16; i++) { if ((reg & 0x1) == 1) { data.Write(false); } else { data.Write(true); } clock.Write(true); clock.Write(false); reg >>= 1; } latch.Write(true); latch.Write(false); }
private uint ReadData() { int bitCount; uint data = 0; _cs.Write(false); { for (bitCount = 31; bitCount >= 0; bitCount--) { _clk.Write(true); if (_miso.Read()) { data |= (uint)(1 << bitCount); } _clk.Write(false); } } _cs.Write(true); return(data); }
// This method is run when the mainboard is powered up or reset. void ProgramStarted() { Debug.Print("Program Started"); _relay = extender.SetupDigitalOutput(Socket.Pin.Three, _relayState); var timer = new GT.Timer(1000); timer.Tick += timer1 => { _relayState = !_relayState; _relay.Write(_relayState); }; timer.Start(); }
/// <summary> /// Clears all registers. /// </summary> public void Clear() { if (!reSized) { ErrorPrint("The array has not been sixed yet. Please indicate how many modules are chained before continuing"); } Enable.Write(true); CLR.Write(false); System.Threading.Thread.Sleep(10); byte[] clear = new byte[1] { 0 }; spi.Write(clear); CLR.Write(true); Enable.Write(false); for (int i = 0; i < data.Length; i++) { data[i] = 0x0; } }
/// <summary> /// Turns on the module's LED. /// </summary> public void TurnLEDOn() { led.Write(true); }
/// <summary> /// Turns the heating element on or off. This may take up to 10 seconds befre a proper reading is taken. /// </summary> /// <param name="bOn">True to turn the element on, false to turn it off.</param> public void SetHeatingElement(bool bOn) { heatingElementEnable.Write(bOn); }
private void Reset() { pinReset.Write(false); Thread.Sleep(150); pinReset.Write(true); }
/// <summary> /// Used to set a motor's speed. /// <param name="_motorSide">The motor <see cref="Motor"/> you are setting the speed for.</param> /// <param name="_newSpeed"> The new speed that you want to set the current motor to.</param> /// </summary> public void MoveMotor(Motor _motorSide, int _newSpeed) { // Make sure the speed is within an acceptable range. if (_newSpeed > 100 || _newSpeed < -100) { new ArgumentException("New motor speed outside the acceptable range (-100-100)", "_newSpeed"); } ////////////////////////////////////////////////////////////////////////////////// // Motor1 ////////////////////////////////////////////////////////////////////////////////// if (_motorSide == Motor.Motor2) { // Determine the direction we are going to go. if (_newSpeed == 0) { //if (m_lastSpeed1 == 0) m_Direction1.Write(false); m_Pwm1.Set(Frequency, 0.01); } else if (_newSpeed < 0) { // Set direction and power. m_Direction1.Write(true); ///////////////////////////////////////////////////////////////////////////// // Quick fix for current PWM issue double fix = (double)((100 - System.Math.Abs(_newSpeed)) / 100.0); if (fix >= 1.0) { fix = 0.99; } if (fix <= 0.0) { fix = 0.01; } ///////////////////////////////////////////////////////////////////////////// m_Pwm1.Set(Frequency, fix); } else { // Set direction and power. m_Direction1.Write(false); ///////////////////////////////////////////////////////////////////////////// // Quick fix for current PWM issue double fix = (double)(_newSpeed / 100.0); if (fix >= 1.0) { fix = 0.99; } if (fix <= 0.0) { fix = 0.01; } ///////////////////////////////////////////////////////////////////////////// m_Pwm1.Set(Frequency, fix); } // Save our speed m_lastSpeed1 = _newSpeed; } ////////////////////////////////////////////////////////////////////////////////// // Motor2 ////////////////////////////////////////////////////////////////////////////////// else { // Determine the direction we are going to go. if (_newSpeed == 0) { //if( m_lastSpeed2 == 0) m_Direction2.Write(false); m_Pwm2.Set(Frequency, 0.01); } else if (_newSpeed < 0) { // Set direction and power. m_Direction2.Write(true); ///////////////////////////////////////////////////////////////////////////// // Quick fix for current PWM issue double fix = (double)((100 - System.Math.Abs(_newSpeed)) / 100.0); if (fix >= 1.0) { fix = 0.99; } if (fix <= 0.0) { fix = 0.01; } ///////////////////////////////////////////////////////////////////////////// m_Pwm2.Set(Frequency, fix); } else { // Set direction and power. m_Direction2.Write(false); ///////////////////////////////////////////////////////////////////////////// // Quick fix for current PWM issue double fix = (double)(_newSpeed / 100.0); if (fix >= 1.0) { fix = 0.99; } if (fix <= 0.0) { fix = 0.01; } ///////////////////////////////////////////////////////////////////////////// m_Pwm2.Set(Frequency, fix); } // Save our speed m_lastSpeed2 = _newSpeed; } ////////////////////////////////////////////////////////////////////////////////// }
/// <summary> /// Enables or disables the display backlight. /// </summary> /// <param name="state">The state to set the backlight to.</param> public void SetBacklight(bool state) { pinBacklight.Write(state); }
/// <summary> /// Enables the outputs to the relays. /// </summary> private void EnableOutputs() { enable.Write(false); }
private void SoftwareSPI_WriteRead(byte[] write, byte[] read) { int writeLen = write.Length; int readLen = 0; if (read != null) { readLen = read.Length; for (int i = 0; i < readLen; i++) { read[i] = 0; } } int loopLen = (writeLen < readLen ? readLen : writeLen); byte w = 0; CS.Write(false); // per byte for (int len = 0; len < loopLen; len++) { if (len < writeLen) { w = write[len]; } byte mask = 0x80; // per bit for (int i = 0; i < 8; i++) { CLOCK.Write(false); if ((w & mask) == mask) { MOSI.Write(true); } else { MOSI.Write(false); } CLOCK.Write(true); if (true == MISO.Read()) { if (read != null) { read[len] |= mask; } } mask >>= 1; } MOSI.Write(false); CLOCK.Write(false); } Thread.Sleep(20); CS.Write(true); }
/// <summary> /// Attempts to enable writing to the flash, and returns the result. /// </summary> /// <returns>True is writing is enabled, false if it is not</returns> public bool WriteEnable() { ClearBuffers(); writeData[0] = CMD_WRITE_ENABLE; statusLED.Write(true); spi.Write(writeData); writeData[0] = CMD_READ_STATUS; spi.WriteRead(writeData, readData); statusLED.Write(false); return((readData[1] & 0x2) != 0); }