ArmandoCircuitos
Inicio
Electronica
Programacion
Resultado
Codigo
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Dado_electronico_UART_01 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } SolidBrush brocha1; Graphics puntos; byte[] buffer = { 1 }; byte cnt = 1; byte num = 0; private void Form1_Load(object sender, EventArgs e) { serialPort1.Open(); serialPort1.Write(buffer, 0, 1); } private void button1_MouseDown(object sender, MouseEventArgs e) { timer1.Enabled = true; button1.Text = "Suelte para detener"; } private void panel1_Paint(object sender, PaintEventArgs e) { brocha1 = new SolidBrush(Color.Black); puntos = e.Graphics; if ((cnt == 1) || (cnt == 3) || (cnt == 5)) { puntos.FillEllipse(brocha1, 80, 80, 40, 40); // 1, 3, 5 num += 1; } if ((cnt == 2) || (cnt == 3) || (cnt == 4) || (cnt == 5) || (cnt == 6)) { puntos.FillEllipse(brocha1, 140, 20, 40, 40); // 2, 3, 4, 5, 6 puntos.FillEllipse(brocha1, 20, 140, 40, 40); // 2, 3, 4, 5, 6 num += 2; } if ((cnt == 4) || (cnt == 5) || (cnt == 6)) { puntos.FillEllipse(brocha1, 20, 20, 40, 40); // 4, 5, 6 puntos.FillEllipse(brocha1, 140, 140, 40, 40); // 4, 5, 6 num += 4; } if (cnt == 6) { puntos.FillEllipse(brocha1, 20, 80, 40, 40); // 6 puntos.FillEllipse(brocha1, 140, 80, 40, 40); // 6 num += 8; } buffer[0] = num; serialPort1.Write(buffer, 0, 1); num = 0; } private void button1_MouseUp(object sender, MouseEventArgs e) { timer1.Enabled = false; button1.Text = "Mantenga presionado para lanzar"; } private void timer1_Tick(object sender, EventArgs e) { panel1.Invalidate(); if (cnt >= 6) cnt = 1; else cnt++; } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { buffer[0] = 0; serialPort1.Write(buffer, 0, 1); serialPort1.Close(); } } }
Descarga del archivo
Descargar archivo