Hej alle endnu engang.
Jeg står nu med et nyt besynderligt problem.? Kan ikke helt rigtig finde rundt i det og hvordan det skal forklares, men vil gøre mit bedste ..
Det er således, at jeg jo som sagt er i gang med et lyskryds, som så køre i det der bliver rød, gult grønt, gult rød osv.
Nu er det sådan, at der er ni forskellige knapper, og i hver knap er der en rød og gul lampe ved siden af. Jeg har så programmert det til at være rødt, medmindre man trykker på en knap, hvor den så bliver rød.
Men men men, når jeg så køre programmet, og jeg intet trykker, så går der fuldstændigt ged i den, også selvom jeg trykker? Den ene lyser grønt, de orange lamper lyser.
Dog, sletter jeg koderne til lampe 4-9 men beholder de resterende 1-4 så køre den fuldstændigt perfekt uden fejl.
Koden er lidt lang, men håber ikke det betyder noget ?
"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace Projekt_2010
{
class Program
{
/// <summary>
///
/// </summary>
/// <param name="adress"></param>
/// <param name="value"></param> [DllImport("inpout32.dll", EntryPoint = "Out32")]
public static extern void Output(int adress, int value);
[DllImport("inpout32.dll", EntryPoint = "Inp32")]
public static extern short Input(int adress);
/// <summary>
///
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="Farve"></param> static void SetLys(int x, int y, ConsoleColor Farve) {
Console.SetCursorPosition(x, y);
Console.ForegroundColor = Farve;
Console.Write("¦");
}
/// <summary>
///
/// </summary>
/// <param name="nr"></param>
/// <param name="lampe"></param> static void Setlampe(int nr, int lampe) {
Output(0x378, nr);
strobe();
Output(0x378, lampe);
strobe();
}
/// <summary>
///
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="nr"></param>
/// <param name="lampe"></param>
/// <param name="Farve"></param>
/// <param name="?"></param> static void SetLysFod(int x, int y, ConsoleColor Farve, int nr, int lampe) {
Console.SetCursorPosition(x, y);
Console.ForegroundColor = Farve;
Console.Write("¦");
Output(0x378, nr);
strobe();
Output(0x378, lampe);
strobe();
}
/// <summary>
///
/// </summary> static void strobe() {
Output(0x37A, 0x1);
Output(0x37A, 0x0);
}
/// <summary>
///
/// </summary>
/// <param name="Nr"></param>
/// <param name="Nr1"></param>
/// <param name="Lampe"></param>
/// <param name="Lampe1"></param> static void Lyskryds(int Nr, int Nr1, int Lampe, int Lampe1) {
int kontakt;
Output(0x378, Nr);
strobe();
kontakt = Input(0x379);
if (kontakt == 126)
{
Output(0x378, Nr1);
strobe();
Output(0x378, Lampe);
strobe();
}
else
{
Output(0x378, Lampe1);
strobe();
}
}
static void Main(string[] args) {
Console.BackgroundColor = ConsoleColor.DarkGray;
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.Clear();
Output(0x378, 0xC0);
strobe();
Console.CursorVisible = false;
while (true)
{
// -- // -- // -- // -> Tænder rød fra 1-4. <- // -- // -- // -- // Setlampe(0x00, 0x81);
SetLys(14, 14, ConsoleColor.Red);
Setlampe(0x01, 0x81);
SetLys(16, 14, ConsoleColor.Red);
Setlampe(0x02, 0x81);
SetLys(15, 15, ConsoleColor.Red);
Setlampe(0x03, 0x81);
SetLys(15, 13, ConsoleColor.Red);
// Beholder jeg koderne herfra og nedefter, så laver den underlige ting,
// Men sletter jeg dem, køre den fint ? Setlampe(0x04, 0x81);
SetLys(23, 6, ConsoleColor.Red);
SetLys(23, 15, ConsoleColor.Red);
Setlampe(0x05, 0x81);
SetLys(25, 14, ConsoleColor.Red);
SetLys(23, 22, ConsoleColor.Red);
Setlampe(0x06, 0x81);
SetLys(7, 22, ConsoleColor.Red);
SetLys(7, 14, ConsoleColor.Red);
Setlampe(0x07, 0x81);
SetLys(5, 14, ConsoleColor.Red);
SetLys(7, 6, ConsoleColor.Red);
Setlampe(0x08, 0x81);
SetLys(11, 5, ConsoleColor.Red);
SetLys(19, 5, ConsoleColor.Red);
Setlampe(0x09, 0x81);
SetLys(19, 23, ConsoleColor.Red);
SetLys(11, 23, ConsoleColor.Red);
// Slut
Thread.Sleep(1000);
// -- // -- // -- // -> Midterkryds - Vest, Øst. <- // -- // -- // -- // SetLys(14, 14, ConsoleColor.DarkGray);
SetLys(16, 14, ConsoleColor.DarkGray);
Setlampe(0x00, 0x83);
SetLys(17, 14, ConsoleColor.Yellow);
Setlampe(0x01, 0x83);
SetLys(13, 14, ConsoleColor.Yellow);
System.Threading.Thread.Sleep(1000);
SetLys(17, 14, ConsoleColor.DarkGray);
SetLys(13, 14, ConsoleColor.DarkGray);
Setlampe(0x00, 0x84);
SetLys(18, 14, ConsoleColor.Green);
Setlampe(0x01, 0x84);
SetLys(12, 14, ConsoleColor.Green);
System.Threading.Thread.Sleep(1000);
SetLys(18, 14, ConsoleColor.DarkGray);
SetLys(12, 14, ConsoleColor.DarkGray);
Setlampe(0x00, 0x82);
SetLys(17, 14, ConsoleColor.Yellow);
Setlampe(0x01, 0x82);
SetLys(13, 14, ConsoleColor.Yellow);
System.Threading.Thread.Sleep(1000);
SetLys(17, 14, ConsoleColor.DarkGray);
SetLys(13, 14, ConsoleColor.DarkGray);
Setlampe(0x00, 0x81);
SetLys(14, 14, ConsoleColor.Red);
Setlampe(0x01, 0x81);
SetLys(16, 14, ConsoleColor.Red);
// -- // -- // -- // -> Drejepile - Vest, Øst. <- // -- // -- // -- //
System.Threading.Thread.Sleep(1000);
SetLys(14, 14, ConsoleColor.DarkGray);
SetLys(16, 14, ConsoleColor.DarkGray);
Setlampe(0x00, 0x88);
SetLys(18, 15, ConsoleColor.Green);
Setlampe(0x01, 0x88);
SetLys(12, 13, ConsoleColor.Green);
System.Threading.Thread.Sleep(1000);
SetLys(18, 15, ConsoleColor.DarkGray);
SetLys(12, 13, ConsoleColor.DarkGray);
Setlampe(0x00, 0x81);
SetLys(14, 14, ConsoleColor.Red);
Setlampe(0x01, 0x81);
SetLys(16, 14, ConsoleColor.Red);
Setlampe(0x02, 0x81);
SetLys(15, 15, ConsoleColor.Red);
Setlampe(0x03, 0x81);
SetLys(15, 13, ConsoleColor.Red);
System.Threading.Thread.Sleep(1000);
// -- // -- // -- // -> Midterkryds - Nord, Syd. <- // -- // -- // -- // SetLys(15, 15, ConsoleColor.DarkGray);
SetLys(15, 13, ConsoleColor.DarkGray);
Setlampe(0x02, 0x83);
SetLys(15, 12, ConsoleColor.Yellow);
Setlampe(0x03, 0x83);
SetLys(15, 16, ConsoleColor.Yellow);
System.Threading.Thread.Sleep(1000);
// -- // -- // -- // -> Fodgængerfelt - Nord, Syd. <- // -- // -- // -- // SetLys(15, 12, ConsoleColor.DarkGray);
SetLys(15, 16, ConsoleColor.DarkGray);
Setlampe(0x02, 0x84);
SetLys(15, 11, ConsoleColor.Green);
Setlampe(0x03, 0x84);
SetLys(15, 17, ConsoleColor.Green);
System.Threading.Thread.Sleep(1000);
SetLys(15, 11, ConsoleColor.DarkGray);
SetLys(15, 17, ConsoleColor.DarkGray);
Setlampe(0x02, 0x82);
SetLys(15, 12, ConsoleColor.Yellow);
Setlampe(0x03, 0x82);
SetLys(15, 16, ConsoleColor.Yellow);
System.Threading.Thread.Sleep(1000);
SetLys(15, 12, ConsoleColor.DarkGray);
SetLys(15, 16, ConsoleColor.DarkGray);
Setlampe(0x02, 0x81);
SetLys(15, 15, ConsoleColor.Red);
Setlampe(0x03, 0x81);
SetLys(15, 13, ConsoleColor.Red);
// -- // -- // -- // -> Drejepile - Nord, Syd. <- // -- // -- // -- //
System.Threading.Thread.Sleep(1000);
SetLys(15, 15, ConsoleColor.DarkGray);
SetLys(15, 13, ConsoleColor.DarkGray);
Setlampe(0x02, 0x90);
SetLys(14, 11, ConsoleColor.Green);
Setlampe(0x03, 0x90);
SetLys(16, 17, ConsoleColor.Green);
System.Threading.Thread.Sleep(1000);
SetLys(14, 11, ConsoleColor.DarkGray);
SetLys(16, 17, ConsoleColor.DarkGray);
Setlampe(0x02, 0x81);
SetLys(15, 15, ConsoleColor.Red);
Setlampe(0x03, 0x81);
SetLys(15, 13, ConsoleColor.Red);
// -- // -- // -- // -> Starter forfra igen. <- // -- // -- // -- //
}
}
}
}
"
Indlæg senest redigeret d. 07.08.2010 02:33 af Bruger #15964