Last active
August 29, 2015 14:24
-
-
Save fferegrino/22cda60be970e98c90a1 to your computer and use it in GitHub Desktop.
A class to control a Bubble Display 7 Segments
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
using System; | |
using Microsoft.SPOT; | |
using Microsoft.SPOT.Hardware; | |
using System.Threading; | |
public class Bubble7 | |
{ | |
public OutputPort D1 { get; private set; } | |
public OutputPort D2 { get; private set; } | |
public OutputPort D3 { get; private set; } | |
public OutputPort D4 { get; private set; } | |
private OutputPort[] segments; | |
public Bubble7(Cpu.Pin a, Cpu.Pin b, | |
Cpu.Pin c, Cpu.Pin d, Cpu.Pin e, | |
Cpu.Pin f, Cpu.Pin g, Cpu.Pin d1, | |
Cpu.Pin d2, Cpu.Pin d3, Cpu.Pin d4) | |
{ | |
segments = new OutputPort[7]; | |
segments[0] = new OutputPort(a, false); | |
segments[1] = new OutputPort(b, false); | |
segments[2] = new OutputPort(c, false); | |
segments[3] = new OutputPort(d, false); | |
segments[4] = new OutputPort(e, false); | |
segments[5] = new OutputPort(f, false); | |
segments[6] = new OutputPort(g, false); | |
D1 = new OutputPort(d1, false); | |
D2 = new OutputPort(d2, false); | |
D3 = new OutputPort(d3, false); | |
D4 = new OutputPort(d4, false); | |
} | |
private static bool[][] Numbers = new bool[][] { | |
new bool[] { true, true, true, true, true, true, false }, | |
new bool[] { false, true, true, false, false, false, false }, | |
new bool[] { true, true, false, true, true, false, true }, | |
new bool[] { true, true, true, true, false, false, true }, | |
new bool[] { false, true, true, false, false, true, true }, | |
new bool[] { true, false, true, true, false, true, true }, | |
new bool[] { false, false, true, true, true, true, true }, | |
new bool[] { true, true, true, false, false, false, false }, | |
new bool[] { true, true, true, true, true, true, true }, | |
new bool[] { true, true, true, false, false, true, true } | |
}; | |
/// <summary> | |
/// Envía un solo dígito al bubble display | |
/// </summary> | |
/// <param name="number"></param> | |
public void PrintDigit(int number) | |
{ | |
for (int i = 0; i < 7; i++) | |
{ | |
segments[i].Write(Numbers[number % 10][i]); | |
} | |
} | |
/// <summary> | |
/// Enciende el display seleccionado | |
/// </summary> | |
/// <param name="display"></param> | |
public void TurnOnDisplay(int display) | |
{ | |
D1.Write(display != 1); | |
D2.Write(display != 2); | |
D3.Write(display != 3); | |
D4.Write(display != 4); | |
} | |
/// <summary> | |
/// Imprime un número de hasta 4 dígitos. El retardo en este método es <paramref name="waitTime"/> * <paramref name="loopCount"/> | |
/// </summary> | |
/// <param name="number">El número a imprimir en el display</param> | |
/// <param name="waitTime">El retardo entre el cambio de display</param> | |
/// <param name="loopCount">El número de ciclos que transcurren para que un número se vea bien</param> | |
public void ShowNumber(int number, int waitTime = 5, int loopCount = 1) | |
{ | |
do | |
{ | |
PrintDigit(number / 1000); | |
TurnOnDisplay(1); | |
Thread.Sleep(waitTime); | |
PrintDigit(number / 100); | |
TurnOnDisplay(2); | |
Thread.Sleep(waitTime); | |
PrintDigit(number / 10); | |
TurnOnDisplay(3); | |
Thread.Sleep(waitTime); | |
PrintDigit(number); | |
TurnOnDisplay(4); | |
Thread.Sleep(waitTime); | |
} while (loopCount-- > 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment