Page 6 of 6 FirstFirst ... 456
Results 51 to 54 of 54

Thread: Making a buttonbox - input wanted

  1. #51
    Superkart Pilot Killg0re NL's Avatar
    Join Date
    Sep 2017
    Location
    Netherlands
    Posts
    139
    Platform
    PS4 Pro
    @Zeratall, i see youre working on arduino aswell. Do you fancy teaming up with us? I am not so handy with the UDP stream, but on the electronic and arduino i got some more experience.

  2. #52
    Superkart Pilot Zeratall's Avatar
    Join Date
    Oct 2017
    Posts
    290
    Platform
    PC
    Yep I use uno for all my. Embedded systems stuff. Using arduino uno and then speed controllers to handle about 1200W (got beefy motors). Arduino reads lat and long acceleration from the game using udp.

    Id love to help out in any way, always enjoy working on this kinda stuff.
    The following 2 users likes this Post: Killg0re NL, Maskmagog


  3. #53
    Superkart Pilot Zeratall's Avatar
    Join Date
    Oct 2017
    Posts
    290
    Platform
    PC
    And I finished it this weekend!!! Check it out in the lower right.


    https://youtu.be/Rg9vYtkrmaw
    The following 2 users likes this Post: Killg0re NL, Maskmagog


  4. #54
    Superkart Pilot Maskmagog's Avatar
    Join Date
    Sep 2017
    Posts
    389
    Platform
    XBOX1 X
    This is the code for my buttonbox, in case anyone can benefit from it. As I said before, I'm using Zeratall's (old) library in C#. You can find on Github here: https://github.com/Zdetier/RST_UDP

    Some things work, some don't. The parts I really needed was fuel, damage, oil/water temp and flags. The game is a bit inconsistent with sending flags, it seems.

    The parts I changed is, first I added a few more definitions in the PCars2_UDP.cs file, Here is my complete file:
    Code:
    using System;
    using System.IO;
    using System.Net;
    using System.Net.Sockets;
     
    
    namespace PcarsUDP
    {
     
        class PCars2_UDP
        {
            const int UDP_STREAMER_CAR_PHYSICS_HANDLER_VERSION = 2;
            const int TYRE_NAME_LENGTH_MAX = 40;
            const int PARTICIPANT_NAME_LENGTH_MAX = 64;
            const int PARTICIPANTS_PER_PACKET = 16;
            const int UDP_STREAMER_PARTICIPANTS_SUPPORTED = 32;
            const int TRACKNAME_LENGTH_MAX = 64;
            const int VEHICLE_NAME_LENGTH_MAX = 64;
            const int CLASS_NAME_LENGTH_MAX = 20;
            const int VEHICLES_PER_PACKET = 16;
            const int CLASSES_SUPPORTED_PER_PACKET = 60;
            const int UDP_STREAMER_TIMINGS_HANDLER_VERSION = 1;
            const int UDP_STREAMER_TIME_STATS_HANDLER_VERSION = 1;
            const int UDP_STREAMER_PARTICIPANT_VEHICLE_NAMES_HANDLER_VERSION = 2;
            const int UDP_STREAMER_GAME_STATE_HANDLER_VERSION = 2;
            
    
            private UdpClient _listener;
            private IPEndPoint _groupEP;
     
            private UInt32 _PacketNumber;
            private UInt32 _CategoryPacketNumber;
            private byte _PartialPacketIndex;
            private byte _PartialPacketNumber;
            private byte _PacketType;
            private byte _PacketVersion;
            private sbyte _ViewedParticipantIndex;
            private byte _UnfilteredThrottle;
            private byte _UnfilteredBrake;
            private sbyte _UnfilteredSteering;
            private byte _UnfilteredClutch;
            private byte _CarFlags;
            private Int16 _OilTempCelsius;
            private UInt16 _OilPressureKPa;
            private Int16 _WaterTempCelsius;
            private UInt16 _WaterPressureKpa;
            private UInt16 _FuelPressureKpa;
            private byte _FuelCapacity;
            private byte _Brake;
            private byte _Throttle;
            private byte _Clutch;
            private float _FuelLevel;
            private float _Speed;
            private UInt16 _Rpm;
            private UInt16 _MaxRpm;
            private sbyte _Steering;
            private byte _GearNumGears;
            private byte _BoostAmount;
            private byte _CrashState;
            private float _OdometerKM;
            private float[] _Orientation = new float[3];
            private float[] _LocalVelocity = new float[3];
            private float[] _WorldVelocity = new float[3];
            private float[] _AngularVelocity = new float[3];
            private float[] _LocalAcceleration = new float[3];
            private float[] _WorldAcceleration = new float[3];
            private float[] _ExtentsCentre = new float[3];
            private byte[] _TyreFlags = new byte[4];
            private byte[] _Terrain = new byte[4];
            private float[] _TyreY = new float[4];
            private float[] _TyreRPS = new float[4];
            private byte[] _TyreTemp = new byte[4];
            private float[] _TyreHeightAboveGround = new float[4];
            private byte[] _TyreWear = new byte[4];
            private byte[] _BrakeDamage = new byte[4];
            private byte[] _SuspensionDamage = new byte[4];
            private Int16[] _BrakeTempCelsius = new Int16[4];
            private UInt16[] _TyreTreadTemp = new UInt16[4];
            private UInt16[] _TyreLayerTemp = new UInt16[4];
            private UInt16[] _TyreCarcassTemp = new UInt16[4];
            private UInt16[] _TyreRimTemp = new UInt16[4];
            private UInt16[] _TyreInternalAirTemp = new UInt16[4];
            private UInt16[] _TyreTempLeft = new UInt16[4];
            private UInt16[] _TyreTempCenter = new UInt16[4];
            private UInt16[] _TyreTempRight = new UInt16[4];
            private float[] _WheelLocalPositionY = new float[4];
            private float[] _RideHeight = new float[4];
            private float[] _SuspensionTravel = new float[4];
            private float[] _SuspensionVelocity = new float[4];
            private UInt16[] _SuspensionRideHeight = new UInt16[4];
            private UInt16[] _AirPressure = new UInt16[4];
            private float _EngineSpeed;
            private float _EngineTorque;
            private byte[] _Wings = new byte[2];
    		private byte _Handbrake;
    		private byte _AeroDamage;
    		private byte _EngineDamage;
    		private UInt32 _Joypad0;
    		private byte _DPad;
    		private byte[][] _TyreCompound = new byte [4][];
    		private float _TurboBoostPressure;
    		private float _FullPosition;
    		private byte _BrakeBias;
    		private UInt32 _TickCount;
    
            //RaceData
    		private float _WorldFastestLapTime;
            private float _PersonalFastestLapTime;
            private float _PersonalFastestSector1Time;
            private float _PersonalFastestSector2Time;
            private float _PersonalFastestSector3Time;
            private float _WorldFastestSector1Time;
            private float _WorldFastestSector2Time;
            private float _WorldFastestSector3Time;
            private float _TrackLength;
    		//private char[] _TrackLocation;// Can't get track names to work
    		//private char[] _TrackVariation;
      //      private char[] _TranslatedTrackLocation;
      //      private char[] _TranslatedTrackVariation;
            private UInt16 _LapsTimeInEvent;                                              
            private sbyte _EnforcedPitStopLap;
    
            //Timing
            private sbyte _NumberParticipants;
            private UInt32 _ParticipantsChangedTimestamp;
            private float _EventTimeRemaining;
            private float _SplitTimeAhead;
            private float _SplitTimeBehind;
            private float _SplitTime;
            private double[,] _ParticipantInfo = new double[32, 16];
    
            //Game Data
            private UInt16 _BuildVersionNumber;
            private byte _GameState;
            private sbyte  _AmbientTemperature;
            private sbyte _TrackTemperature;
            private double _RainDensity;
            private double _SnowDensity;
            private sbyte _WindSpeed;
            private sbyte _WindDirectionX;
            private sbyte _WindDirectionY;
    
            // Participant Stats Info
            private double[,] _ParticipantStatsInfo = new double[32, 16];
    
    
            public PCars2_UDP(UdpClient listen, IPEndPoint group)
            {
                _listener = listen;
                _groupEP = group;
            }
    
            public void readPackets()
            {
                byte[] UDPpacket = listener.Receive(ref _groupEP);
                Stream stream = new MemoryStream(UDPpacket);
                var binaryReader = new BinaryReader(stream);
    
                ReadBaseUDP(stream, binaryReader);
                if (PacketType == 0)
                {
                    ReadTelemetryData(stream, binaryReader);         
                }
                else if (PacketType == 1)
                {
                    ReadRaceData(stream, binaryReader);
                }
                else if (PacketType == 3)
                {
                    ReadTimings(stream, binaryReader);
                }
                else if (PacketType == 4)
                {
                    ReadGameData(stream, binaryReader);
                }
                else if (PacketType == 7)
                {
                    ReadParticipantsStatsInfo(stream, binaryReader);
                }
            }
    
            public void ReadBaseUDP(Stream stream, BinaryReader binaryReader)
            {
                stream.Position = 0;
                PacketNumber = binaryReader.ReadUInt32();
                CategoryPacketNumber = binaryReader.ReadUInt32();
                PartialPacketIndex = binaryReader.ReadByte();
                PartialPacketNumber = binaryReader.ReadByte();
                PacketType = binaryReader.ReadByte();
                PacketVersion = binaryReader.ReadByte();
            }
     
            public void ReadTelemetryData(Stream stream, BinaryReader binaryReader)
            {
                stream.Position = 12;
    			
    			ViewedParticipantIndex = binaryReader.ReadSByte();
                UnfilteredThrottle = binaryReader.ReadByte();
                UnfilteredBrake = binaryReader.ReadByte();
                UnfilteredSteering = binaryReader.ReadSByte();
                UnfilteredClutch = binaryReader.ReadByte();
                CarFlags = binaryReader.ReadByte();
                OilTempCelsius = binaryReader.ReadInt16();
                OilPressureKPa = binaryReader.ReadUInt16();
                WaterTempCelsius = binaryReader.ReadInt16();
                WaterPressureKpa = binaryReader.ReadUInt16();
                FuelPressureKpa = binaryReader.ReadUInt16();
                FuelCapacity = binaryReader.ReadByte();
                Brake = binaryReader.ReadByte();
                Throttle = binaryReader.ReadByte();
                Clutch = binaryReader.ReadByte();
                FuelLevel = binaryReader.ReadSingle();
                Speed = binaryReader.ReadSingle();
                Rpm = binaryReader.ReadUInt16();
                MaxRpm = binaryReader.ReadUInt16();
                Steering = binaryReader.ReadSByte();
                GearNumGears = binaryReader.ReadByte();
                BoostAmount = binaryReader.ReadByte();
                CrashState = binaryReader.ReadByte();
                OdometerKM = binaryReader.ReadSingle();
     
                Orientation[0] = binaryReader.ReadSingle();
                Orientation[1] = binaryReader.ReadSingle();
                Orientation[2] = binaryReader.ReadSingle();
     
                LocalVelocity[0] = binaryReader.ReadSingle();
                LocalVelocity[1] = binaryReader.ReadSingle();
                LocalVelocity[2] = binaryReader.ReadSingle();
     
                WorldVelocity[0] = binaryReader.ReadSingle();
                WorldVelocity[1] = binaryReader.ReadSingle();
                WorldVelocity[2] = binaryReader.ReadSingle();
     
                AngularVelocity[0] = binaryReader.ReadSingle();
                AngularVelocity[1] = binaryReader.ReadSingle();
                AngularVelocity[2] = binaryReader.ReadSingle();
     
                LocalAcceleration[0] = binaryReader.ReadSingle();
                LocalAcceleration[1] = binaryReader.ReadSingle();
                LocalAcceleration[2] = binaryReader.ReadSingle();
     
                WorldAcceleration[0] = binaryReader.ReadSingle();
                WorldAcceleration[1] = binaryReader.ReadSingle();
                WorldAcceleration[2] = binaryReader.ReadSingle();
     
                ExtentsCentre[0] = binaryReader.ReadSingle();
                ExtentsCentre[1] = binaryReader.ReadSingle();
                ExtentsCentre[2] = binaryReader.ReadSingle();
     
                TyreFlags[0] = binaryReader.ReadByte();
                TyreFlags[1] = binaryReader.ReadByte();
                TyreFlags[2] = binaryReader.ReadByte();
                TyreFlags[3] = binaryReader.ReadByte();
     
                Terrain[0] = binaryReader.ReadByte();
                Terrain[1] = binaryReader.ReadByte();
                Terrain[2] = binaryReader.ReadByte();
                Terrain[3] = binaryReader.ReadByte();
     
                TyreY[0] = binaryReader.ReadSingle();
                TyreY[1] = binaryReader.ReadSingle();
                TyreY[2] = binaryReader.ReadSingle();
                TyreY[3] = binaryReader.ReadSingle();
     
                TyreRPS[0] = binaryReader.ReadSingle();
                TyreRPS[1] = binaryReader.ReadSingle();
                TyreRPS[2] = binaryReader.ReadSingle();
                TyreRPS[3] = binaryReader.ReadSingle();
     
                TyreTemp[0] = binaryReader.ReadByte();
                TyreTemp[1] = binaryReader.ReadByte();
                TyreTemp[2] = binaryReader.ReadByte();
                TyreTemp[3] = binaryReader.ReadByte();
     
                TyreHeightAboveGround[0] = binaryReader.ReadSingle();
                TyreHeightAboveGround[1] = binaryReader.ReadSingle();
                TyreHeightAboveGround[2] = binaryReader.ReadSingle();
                TyreHeightAboveGround[3] = binaryReader.ReadSingle();
     
                TyreWear[0] = binaryReader.ReadByte();
                TyreWear[1] = binaryReader.ReadByte();
                TyreWear[2] = binaryReader.ReadByte();
                TyreWear[3] = binaryReader.ReadByte();
     
                BrakeDamage[0] = binaryReader.ReadByte();
                BrakeDamage[1] = binaryReader.ReadByte();
                BrakeDamage[2] = binaryReader.ReadByte();
                BrakeDamage[3] = binaryReader.ReadByte();
     
                SuspensionDamage[0] = binaryReader.ReadByte();
                SuspensionDamage[1] = binaryReader.ReadByte();
                SuspensionDamage[2] = binaryReader.ReadByte();
                SuspensionDamage[3] = binaryReader.ReadByte();
     
                BrakeTempCelsius[0] = binaryReader.ReadInt16();
                BrakeTempCelsius[1] = binaryReader.ReadInt16();
                BrakeTempCelsius[2] = binaryReader.ReadInt16();
                BrakeTempCelsius[3] = binaryReader.ReadInt16();
     
                TyreTreadTemp[0] = binaryReader.ReadUInt16();
                TyreTreadTemp[1] = binaryReader.ReadUInt16();
                TyreTreadTemp[2] = binaryReader.ReadUInt16();
                TyreTreadTemp[3] = binaryReader.ReadUInt16();
     
                TyreLayerTemp[0] = binaryReader.ReadUInt16();
                TyreLayerTemp[1] = binaryReader.ReadUInt16();
                TyreLayerTemp[2] = binaryReader.ReadUInt16();
                TyreLayerTemp[3] = binaryReader.ReadUInt16();
     
                TyreCarcassTemp[0] = binaryReader.ReadUInt16();
                TyreCarcassTemp[1] = binaryReader.ReadUInt16();
                TyreCarcassTemp[2] = binaryReader.ReadUInt16();
                TyreCarcassTemp[3] = binaryReader.ReadUInt16();
     
                TyreRimTemp[0] = binaryReader.ReadUInt16();
                TyreRimTemp[1] = binaryReader.ReadUInt16();
                TyreRimTemp[2] = binaryReader.ReadUInt16();
                TyreRimTemp[3] = binaryReader.ReadUInt16();
     
                TyreInternalAirTemp[0] = binaryReader.ReadUInt16();
                TyreInternalAirTemp[1] = binaryReader.ReadUInt16();
                TyreInternalAirTemp[2] = binaryReader.ReadUInt16();
                TyreInternalAirTemp[3] = binaryReader.ReadUInt16();
     
                TyreTempLeft[0] = binaryReader.ReadUInt16();
                TyreTempLeft[1] = binaryReader.ReadUInt16();
                TyreTempLeft[2] = binaryReader.ReadUInt16();
                TyreTempLeft[3] = binaryReader.ReadUInt16();
     
                TyreTempCenter[0] = binaryReader.ReadUInt16();
                TyreTempCenter[1] = binaryReader.ReadUInt16();
                TyreTempCenter[2] = binaryReader.ReadUInt16();
                TyreTempCenter[3] = binaryReader.ReadUInt16();
     
                TyreTempRight[0] = binaryReader.ReadUInt16();
                TyreTempRight[1] = binaryReader.ReadUInt16();
                TyreTempRight[2] = binaryReader.ReadUInt16();
                TyreTempRight[3] = binaryReader.ReadUInt16();
     
                WheelLocalPositionY[0] = binaryReader.ReadSingle();
                WheelLocalPositionY[1] = binaryReader.ReadSingle();
                WheelLocalPositionY[2] = binaryReader.ReadSingle();
                WheelLocalPositionY[3] = binaryReader.ReadSingle();
     
                RideHeight[0] = binaryReader.ReadSingle();
                RideHeight[1] = binaryReader.ReadSingle();
                RideHeight[2] = binaryReader.ReadSingle();
                RideHeight[3] = binaryReader.ReadSingle();
     
                SuspensionTravel[0] = binaryReader.ReadSingle();
                SuspensionTravel[1] = binaryReader.ReadSingle();
                SuspensionTravel[2] = binaryReader.ReadSingle();
                SuspensionTravel[3] = binaryReader.ReadSingle();
     
                SuspensionVelocity[0] = binaryReader.ReadSingle();
                SuspensionVelocity[1] = binaryReader.ReadSingle();
                SuspensionVelocity[2] = binaryReader.ReadSingle();
                SuspensionVelocity[3] = binaryReader.ReadSingle();
     
                SuspensionRideHeight[0] = binaryReader.ReadUInt16();
                SuspensionRideHeight[1] = binaryReader.ReadUInt16();
                SuspensionRideHeight[2] = binaryReader.ReadUInt16();
                SuspensionRideHeight[3] = binaryReader.ReadUInt16();
     
                AirPressure[0] = binaryReader.ReadUInt16();
                AirPressure[1] = binaryReader.ReadUInt16();
                AirPressure[2] = binaryReader.ReadUInt16();
                AirPressure[3] = binaryReader.ReadUInt16();
     
                EngineSpeed = binaryReader.ReadSingle();
                EngineTorque = binaryReader.ReadSingle();
     
                Wings[0] = binaryReader.ReadByte();
                Wings[1] = binaryReader.ReadByte();
    			
    			Handbrake = binaryReader.ReadByte();
    			
    			AeroDamage = binaryReader.ReadByte();
    			EngineDamage = binaryReader.ReadByte();
    			
    			Joypad0 = binaryReader.ReadUInt32();
    			DPad = binaryReader.ReadByte();
    			
    			TyreCompound[0] = binaryReader.ReadBytes(TYRE_NAME_LENGTH_MAX);
    			TyreCompound[1] = binaryReader.ReadBytes(TYRE_NAME_LENGTH_MAX);
    			TyreCompound[2] = binaryReader.ReadBytes(TYRE_NAME_LENGTH_MAX);
    			TyreCompound[3] = binaryReader.ReadBytes(TYRE_NAME_LENGTH_MAX);
    			
    			TurboBoostPressure = binaryReader.ReadSingle();
    
    			FullPosition = binaryReader.ReadSingle();
    			
    			BrakeBias = binaryReader.ReadByte();
    			
    			TickCount = binaryReader.ReadUInt32();
    			
            }
    
            public void ReadRaceData(Stream stream, BinaryReader binaryReader)
            {
                stream.Position = 12;
    
                WorldFastestLapTime = binaryReader.ReadSingle();
                PersonalFastestLapTime = binaryReader.ReadSingle();
                PersonalFastestSector1Time = binaryReader.ReadSingle();
                PersonalFastestSector2Time = binaryReader.ReadSingle();
                PersonalFastestSector3Time = binaryReader.ReadSingle();
                WorldFastestSector1Time = binaryReader.ReadSingle();
                WorldFastestSector2Time = binaryReader.ReadSingle();
                WorldFastestSector3Time = binaryReader.ReadSingle();
                TrackLength = binaryReader.ReadSingle();
                //TrackLocation = binaryReader.ReadChars(TRACKNAME_LENGTH_MAX);
                //TrackVariation = binaryReader.ReadChars(TRACKNAME_LENGTH_MAX);
                //TranslatedTrackLocation = binaryReader.ReadChars(TRACKNAME_LENGTH_MAX);
                //TranslatedTrackVariation = binaryReader.ReadChars(TRACKNAME_LENGTH_MAX);
                LapsTimeInEvent = binaryReader.ReadUInt16();
                EnforcedPitStopLap = binaryReader.ReadSByte();
            }
    
    
            public void ReadTimings(Stream stream, BinaryReader binaryReader)
            {
                stream.Position = 12;
                NumberParticipants = binaryReader.ReadSByte();
                ParticipantsChangedTimestamp = binaryReader.ReadUInt32();
                EventTimeRemaining = binaryReader.ReadSingle();
                SplitTimeAhead = binaryReader.ReadSingle();
                SplitTimeBehind = binaryReader.ReadSingle();
                SplitTime = binaryReader.ReadSingle();
    
                for (int i = 0; i < 32; i++)
                {
                    ParticipantInfo[i, 0] = Convert.ToDouble(binaryReader.ReadInt16());  //WorldPosition 
                    ParticipantInfo[i, 1] = Convert.ToDouble(binaryReader.ReadInt16());  //WorldPosition
                    ParticipantInfo[i, 2] = Convert.ToDouble(binaryReader.ReadInt16());  //WorldPosition
                    ParticipantInfo[i, 3] = Convert.ToDouble(binaryReader.ReadInt16());  //Orientation
                    ParticipantInfo[i, 4] = Convert.ToDouble(binaryReader.ReadInt16()); //Orientation 
                    ParticipantInfo[i, 5] = Convert.ToDouble(binaryReader.ReadInt16());  //Orientation
                    ParticipantInfo[i, 6] = Convert.ToDouble(binaryReader.ReadUInt16());  //sCurrentLapDistance
                    ParticipantInfo[i, 7] = Convert.ToDouble(binaryReader.ReadByte()) - 128;  //sRacePosition
                    byte Sector_ALL = binaryReader.ReadByte();
                    var Sector_Extracted = Sector_ALL & 0x0F;
                    ParticipantInfo[i, 8] = Convert.ToDouble(Sector_Extracted + 1);   //sSector
                    ParticipantInfo[i, 9] = Convert.ToDouble(binaryReader.ReadByte());  //sHighestFlag
                    ParticipantInfo[i, 10] = Convert.ToDouble(binaryReader.ReadByte()); //sPitModeSchedule
                    ParticipantInfo[i, 11] = Convert.ToDouble(binaryReader.ReadUInt16());//sCarIndex
                    ParticipantInfo[i, 12] = Convert.ToDouble(binaryReader.ReadByte()); //sRaceState
                    ParticipantInfo[i, 13] = Convert.ToDouble(binaryReader.ReadByte()); //sCurrentLap
                    ParticipantInfo[i, 14] = Convert.ToDouble(binaryReader.ReadSingle()); //sCurrentTime
                    ParticipantInfo[i, 15] = Convert.ToDouble(binaryReader.ReadSingle());  //sCurrentSectorTime
                }
    
            }
    
            public void ReadGameData(Stream stream, BinaryReader binaryReader)
            {
                stream.Position = 12;
    
                BuildVersionNumber = binaryReader.ReadUInt16();
                GameState = binaryReader.ReadByte();
                AmbientTemperature = binaryReader.ReadSByte();
                TrackTemperature = binaryReader.ReadSByte();
                RainDensity = Convert.ToDouble(binaryReader.ReadByte());
                SnowDensity = Convert.ToDouble(binaryReader.ReadByte());
                WindSpeed = binaryReader.ReadSByte();
                WindDirectionX = binaryReader.ReadSByte();
                WindDirectionY = binaryReader.ReadSByte();
            }
    
            public void ReadParticipantsStatsInfo(Stream stream, BinaryReader binaryReader)
            {
                stream.Position = 12;
    
                for (int i = 0; i < 32; i++)
                {
                    ParticipantStatsInfo[i, 1] = Convert.ToDouble(binaryReader.ReadSingle());  //FastestLap 
                    ParticipantStatsInfo[i, 2] = Convert.ToDouble(binaryReader.ReadSingle());  //LastLap
                    ParticipantStatsInfo[i, 3] = Convert.ToDouble(binaryReader.ReadSingle());  //LastSectorTime
                    ParticipantStatsInfo[i, 4] = Convert.ToDouble(binaryReader.ReadSingle());  //FastestSector1
                    ParticipantStatsInfo[i, 5] = Convert.ToDouble(binaryReader.ReadSingle()); //FastestSector2
                    ParticipantStatsInfo[i, 6] = Convert.ToDouble(binaryReader.ReadSingle());  //FastestSector3
    
                }
    
            }
    
            public void close_UDP_Connection()
            {
                listener.Close();
            }
     
            public UdpClient listener
            {
                get
                {
                    return _listener;
                }
                set
                {
                    _listener = value;
                }
            }
     
            public IPEndPoint groupEP
            {
                get
                {
                    return _groupEP;
                }
                set
                {
                    _groupEP = value;
                }
            }
     
            public UInt32 PacketNumber
            {
                get
                {
                    return _PacketNumber;
                }
                set
                {
                    _PacketNumber = value;
                }
            }
     
            public UInt32 CategoryPacketNumber
            {
                get
                {
                    return _CategoryPacketNumber;
                }
                set
                {
                    _CategoryPacketNumber = value;
                }
            }
     
            public byte PartialPacketIndex
            {
                get
                {
                    return _PartialPacketIndex;
                }
                set
                {
                    _PartialPacketIndex = value;
                }
            }
     
            public byte PartialPacketNumber
            {
                get
                {
                    return _PartialPacketNumber;
                }
                set
                {
                    _PartialPacketNumber = value;
                }
            }
     
            public byte PacketType
            {
                get
                {
                    return _PacketType;
                }
                set
                {
                    _PacketType = value;
                }
            }
     
            public byte PacketVersion
            {
                get
                {
                    return _PacketVersion;
                }
                set
                {
                    _PacketVersion = value;
                }
            }
     
            public sbyte ViewedParticipantIndex
            {
                get
                {
                    return _ViewedParticipantIndex;
                }
                set
                {
                    _ViewedParticipantIndex = value;
                }
            }
     
            public byte UnfilteredThrottle
            {
                get
                {
                    return _UnfilteredThrottle;
                }
                set
                {
                    _UnfilteredThrottle = value;
                }
            }
     
            public byte UnfilteredBrake
            {
                get
                {
                    return _UnfilteredBrake;
                }
                set
                {
                    _UnfilteredBrake = value;
                }
            }
     
            public sbyte UnfilteredSteering
            {
                get
                {
                    return _UnfilteredSteering;
                }
                set
                {
                    _UnfilteredSteering = value;
                }
            }
     
            public byte UnfilteredClutch
            {
                get
                {
                    return _UnfilteredClutch;
                }
                set
                {
                    _UnfilteredClutch = value;
                }
            }
     
            public byte CarFlags
            {
                get
                {
                    return _CarFlags;
                }
                set
                {
                    _CarFlags = value;
                }
            }
     
            public Int16 OilTempCelsius
            {
                get
                {
                    return _OilTempCelsius;
                }
                set
                {
                    _OilTempCelsius = value;
                }
            }
     
            public UInt16 OilPressureKPa
            {
                get
                {
                    return _OilPressureKPa;
                }
                set
                {
                    _OilPressureKPa = value;
                }
            }
     
            public Int16 WaterTempCelsius
            {
                get
                {
                    return _WaterTempCelsius;
                }
                set
                {
                    _WaterTempCelsius = value;
                }
            }
     
            public UInt16 WaterPressureKpa
            {
                get
                {
                    return _WaterPressureKpa;
                }
                set
                {
                    _WaterPressureKpa = value;
                }
            }
     
            public UInt16 FuelPressureKpa
            {
                get
                {
                    return _FuelPressureKpa;
                }
                set
                {
                    _FuelPressureKpa = value;
                }
            }
     
            public byte FuelCapacity
            {
                get
                {
                    return _FuelCapacity;
                }
                set
                {
                    _FuelCapacity = value;
                }
            }
     
            public byte Brake
            {
                get
                {
                    return _Brake;
                }
                set
                {
                    _Brake = value;
                }
            }
     
            public byte Throttle
            {
                get
                {
                    return _Throttle;
                }
                set
                {
                    _Throttle = value;
                }
            }
     
            public byte Clutch
            {
                get
                {
                    return _Clutch;
                }
                set
                {
                    _Clutch = value;
                }
            }
     
            public float FuelLevel
            {
                get
                {
                    return _FuelLevel;
                }
                set
                {
                    _FuelLevel = value;
                }
            }
     
            public float Speed
            {
                get
                {
                    return _Speed;
                }
                set
                {
                    _Speed = value;
                }
            }
     
            public UInt16 Rpm
            {
                get
                {
                    return _Rpm;
                }
                set
                {
                    _Rpm = value;
                }
            }
     
            public UInt16 MaxRpm
            {
                get
                {
                    return _MaxRpm;
                }
                set
                {
                    _MaxRpm = value;
                }
            }
     
            public sbyte Steering
            {
                get
                {
                    return _Steering;
                }
                set
                {
                    _Steering = value;
                }
            }
     
            public byte GearNumGears
            {
                get
                {
                    return _GearNumGears;
                }
                set
                {
                    _GearNumGears = value;
                }
            }
     
            public byte BoostAmount
            {
                get
                {
                    return _BoostAmount;
                }
                set
                {
                    _BoostAmount = value;
                }
            }
     
            public byte CrashState
            {
                get
                {
                    return _CrashState;
                }
                set
                {
                    _CrashState = value;
                }
            }
     
            public float OdometerKM
            {
                get
                {
                    return _OdometerKM;
                }
                set
                {
                    _OdometerKM = value;
                }
            }
     
            public float[] Orientation
            {
                get
                {
                    return _Orientation;
                }
                set
                {
                    _Orientation = value;
                }
            }
     
            public float[] LocalVelocity
            {
                get
                {
                    return _LocalVelocity;
                }
                set
                {
                    _LocalVelocity = value;
                }
            }
     
            public float[] WorldVelocity
            {
                get
                {
                    return _WorldVelocity;
                }
                set
                {
                    _WorldVelocity = value;
                }
            }
     
            public float[] AngularVelocity
            {
                get
                {
                    return _AngularVelocity;
                }
                set
                {
                    _AngularVelocity = value;
                }
            }
     
            public float[] LocalAcceleration
            {
                get
                {
                    return _LocalAcceleration;
                }
                set
                {
                    _LocalAcceleration = value;
                }
            }
     
            public float[] WorldAcceleration
            {
                get
                {
                    return _WorldAcceleration;
                }
                set
                {
                    _WorldAcceleration = value;
                }
            }
     
            public float[] ExtentsCentre
            {
                get
                {
                    return _ExtentsCentre;
                }
                set
                {
                    _ExtentsCentre = value;
                }
            }
     
            public byte[] TyreFlags
            {
                get
                {
                    return _TyreFlags;
                }
                set
                {
                    _TyreFlags = value;
                }
            }
     
            public byte[] Terrain
            {
                get
                {
                    return _Terrain;
                }
                set
                {
                    _Terrain = value;
                }
            }
     
            public float[] TyreY
            {
                get
                {
                    return _TyreY;
                }
                set
                {
                    _TyreY = value;
                }
            }
     
            public float[] TyreRPS
            {
                get
                {
                    return _TyreRPS;
                }
                set
                {
                    _TyreRPS = value;
                }
            }
     
            public byte[] TyreTemp
            {
                get
                {
                    return _TyreTemp;
                }
                set
                {
                    _TyreTemp = value;
                }
            }
     
            public float[] TyreHeightAboveGround
            {
                get
                {
                    return _TyreHeightAboveGround;
                }
                set
                {
                    _TyreHeightAboveGround = value;
                }
            }
     
            public byte[] TyreWear
            {
                get
                {
                    return _TyreWear;
                }
                set
                {
                    _TyreWear = value;
                }
            }
     
            public byte[] BrakeDamage
            {
                get
                {
                    return _BrakeDamage;
                }
                set
                {
                    _BrakeDamage = value;
                }
            }
     
            public byte[] SuspensionDamage
            {
                get
                {
                    return _SuspensionDamage;
                }
                set
                {
                    _SuspensionDamage = value;
                }
            }
     
            public Int16[] BrakeTempCelsius
            {
                get
                {
                    return _BrakeTempCelsius;
                }
                set
                {
                    _BrakeTempCelsius = value;
                }
            }
     
            public UInt16[] TyreTreadTemp
            {
                get
                {
                    return _TyreTreadTemp;
                }
                set
                {
                    _TyreTreadTemp = value;
                }
            }
     
            public UInt16[] TyreLayerTemp
            {
                get
                {
                    return _TyreLayerTemp;
                }
                set
                {
                    _TyreLayerTemp = value;
                }
            }
     
            public UInt16[] TyreCarcassTemp
            {
                get
                {
                    return _TyreCarcassTemp;
                }
                set
                {
                    _TyreCarcassTemp = value;
                }
            }
     
            public UInt16[] TyreRimTemp
            {
                get
                {
                    return _TyreRimTemp;
                }
                set
                {
                    _TyreRimTemp = value;
                }
            }
     
            public UInt16[] TyreInternalAirTemp
            {
                get
                {
                    return _TyreInternalAirTemp;
                }
                set
                {
                    _TyreInternalAirTemp = value;
                }
            }
     
            public UInt16[] TyreTempLeft
            {
                get
                {
                    return _TyreTempLeft;
                }
                set
                {
                    _TyreTempLeft = value;
                }
            }
     
            public UInt16[] TyreTempCenter
            {
                get
                {
                    return _TyreTempCenter;
                }
                set
                {
                    _TyreTempCenter = value;
                }
            }
     
            public UInt16[] TyreTempRight
            {
                get
                {
                    return _TyreTempRight;
                }
                set
                {
                    _TyreTempRight = value;
                }
            }
     
            public float[] WheelLocalPositionY
            {
                get
                {
                    return _WheelLocalPositionY;
                }
                set
                {
                    _WheelLocalPositionY = value;
                }
            }
     
            public float[] RideHeight
            {
                get
                {
                    return _RideHeight;
                }
                set
                {
                    _RideHeight = value;
                }
            }
     
            public float[] SuspensionTravel
            {
                get
                {
                    return _SuspensionTravel;
                }
                set
                {
                    _SuspensionTravel = value;
                }
            }
     
            public float[] SuspensionVelocity
            {
                get
                {
                    return _SuspensionVelocity;
                }
                set
                {
                    _SuspensionVelocity = value;
                }
            }
     
            public UInt16[] SuspensionRideHeight
            {
                get
                {
                    return _SuspensionRideHeight;
                }
                set
                {
                    _SuspensionRideHeight = value;
                }
            }
     
            public UInt16[] AirPressure
            {
                get
                {
                    return _AirPressure;
                }
                set
                {
                    _AirPressure = value;
                }
            }
     
            public float EngineSpeed
            {
                get
                {
                    return _EngineSpeed;
                }
                set
                {
                    _EngineSpeed = value;
                }
            }
     
            public float EngineTorque
            {
                get
                {
                    return _EngineTorque;
                }
                set
                {
                    _EngineTorque = value;
                }
            }
     
            public byte[] Wings
            {
                get
                {
                    return _Wings;
                }
                set
                {
                    _Wings = value;
                }
            }
     
    		public byte Handbrake
            {
                get
                {
                    return _Handbrake;
                }
                set
                {
                    _Handbrake = value;
                }
            }
     
    		    public byte AeroDamage
                {
                    get
                    {
                        return _AeroDamage;
                    }
                    set
                    {
                        _AeroDamage = value;
                    }
                }
    		
    		public byte EngineDamage
            {
                get
                {
                    return _EngineDamage;
                }
                set
                {
                    _EngineDamage = value;
                }
            }
    		
    		public UInt32 Joypad0
            {
                get
                {
                    return _Joypad0;
                }
                set
                {
                    _Joypad0 = value;
                }
            }
    		
    		public byte DPad
            {
                get
                {
                    return _DPad;
                }
                set
                {
                    _DPad = value;
                }
            }
    		
    		public byte[][] TyreCompound
            {
                get
                {
                    return _TyreCompound;
                }
                set
                {
                    _TyreCompound = value;
                }
            }
    		
    		public float TurboBoostPressure
            {
                get
                {
                    return _TurboBoostPressure;
                }
                set
                {
                    _TurboBoostPressure = value;
                }
            }
    		
    		public float FullPosition
            {
                get
                {
                    return _FullPosition;
                }
                set
                {
                    _FullPosition = value;
                }
            }
    		
    		public byte BrakeBias
            {
                get
                {
                    return _BrakeBias;
                }
                set
                {
                    _BrakeBias = value;
                }
            }
    		
    		public UInt32 TickCount
            {
                get
                {
                    return _TickCount;
                }
                set
                {
                    _TickCount = value;
                }
            }
    
            // RaceData
            public float WorldFastestLapTime
            {
                get
                {
                    return _WorldFastestLapTime;
                }
                set
                {
                    _WorldFastestLapTime = value;
                }
            }
    
            public float PersonalFastestLapTime
            {
                get
                {
                    return _PersonalFastestLapTime;
                }
                set
                {
                    _PersonalFastestLapTime = value;
                }
            }
    
            public float PersonalFastestSector1Time
            {
                get
                {
                    return _PersonalFastestSector1Time;
                }
                set
                {
                    _PersonalFastestSector1Time = value;
                }
            }
    
            public float PersonalFastestSector2Time
            {
                get
                {
                    return _PersonalFastestSector2Time;
                }
                set
                {
                    _PersonalFastestSector2Time = value;
                }
            }
    
            public float PersonalFastestSector3Time
            {
                get
                {
                    return _PersonalFastestSector3Time;
                }
                set
                {
                    _PersonalFastestSector3Time = value;
                }
            }
    
            public float WorldFastestSector1Time
            {
                get
                {
                    return _WorldFastestSector1Time;
                }
                set
                {
                    _WorldFastestSector1Time = value;
                }
            }
    
            public float WorldFastestSector2Time
            {
                get
                {
                    return _WorldFastestSector2Time;
                }
                set
                {
                    _WorldFastestSector2Time = value;
                }
            }
    
            public float WorldFastestSector3Time
            {
                get
                {
                    return _WorldFastestSector3Time;
                }
                set
                {
                    _WorldFastestSector3Time = value;
                }
            }
    
            public float TrackLength
            {
                get
                {
                    return _TrackLength;
                }
                set
                {
                    _TrackLength = value;
                }
            }
    
            //   public char[] TrackLocation
            //   {
            //       get
            //       {
            //           return _TrackLocation;
            //       }
            //       set
            //       {
            //           _TrackLocation = value;
            //       }
            //   }
    
            //   public char[] TrackVariation
            //   {
            //       get
            //       {
            //           return _TrackVariation;
            //       }
            //       set
            //       {
            //           _TrackVariation = value;
            //       }
            //   }
    
            //   public char[] TranslatedTrackLocation
            //   {
            //       get
            //       {
            //           return _TranslatedTrackLocation;
            //       }
            //       set
            //       {
            //           _TranslatedTrackLocation = value;
            //       }
            //   }
    
            //   public char[] TranslatedTrackVariation
            //   {
            //       get
            //       {
            //           return _TranslatedTrackVariation;
            //       }
            //       set
            //       {
            //           _TranslatedTrackVariation = value;
            //       }
            //   }
    
            public UInt16 LapsTimeInEvent
            {
                get
                {
                    return _LapsTimeInEvent;
                }
                set
                {
                    _LapsTimeInEvent = value;
                }
            }
    
            public sbyte EnforcedPitStopLap
            {
                get
                {
                    return _EnforcedPitStopLap;
                }
                set
                {
                    _EnforcedPitStopLap = value;
                }
            }
    
            // Timings
            public sbyte NumberParticipants
            {
                get
                {
                    return _NumberParticipants;
                }
                set
                {
                    _NumberParticipants = value;
                }
            }
    
            public UInt32 ParticipantsChangedTimestamp
            {
                get
                {
                    return _ParticipantsChangedTimestamp;
                }
                set
                {
                    _ParticipantsChangedTimestamp = value;
                }
            }
    
            public float EventTimeRemaining
            {
                get
                {
                    return _EventTimeRemaining;
                }
                set
                {
                    _EventTimeRemaining = value;
                }
            }
    
            public float SplitTimeAhead
            {
                get
                {
                    return _SplitTimeAhead;
                }
                set
                {
                    _SplitTimeAhead = value;
                }
            }
    
            public float SplitTimeBehind
            {
                get
                {
                    return _SplitTimeBehind;
                }
                set
                {
                    _SplitTimeBehind = value;
                }
            }
    
            public float SplitTime
            {
                get
                {
                    return _SplitTime;
                }
                set
                {
                    _SplitTime = value;
                }
            }
    
            public double[,] ParticipantInfo
            {
                get
                {
                    return _ParticipantInfo;
                }
                set
                {
                    _ParticipantInfo = value;
                }
            }
    
    		// GameState
            public UInt16 BuildVersionNumber
            {
                get
                {
                    return _BuildVersionNumber;
                }
                set
                {
                    _BuildVersionNumber = value;
                }
            }
    
            public byte GameState
            {
                get
                {
                    return _GameState;
                }
                set
                {
                    _GameState = value;
                }
            }
    
            public sbyte AmbientTemperature
            {
                get
                {
                    return _AmbientTemperature;
                }
                set
                {
                    _AmbientTemperature = value;
                }
            }
    
            public sbyte TrackTemperature
            {
                get
                {
                    return _TrackTemperature;
                }
                set
                {
                    _TrackTemperature = value;
                }
            }
    
            public double RainDensity
            {
                get
                {
                    return _RainDensity;
                }
                set
                {
                    _RainDensity = value;
                }
            }
    
            public double SnowDensity
            {
                get
                {
                    return _SnowDensity;
                }
                set
                {
                    _SnowDensity = value;
                }
            }
    
            public sbyte WindSpeed
            {
                get
                {
                    return _WindSpeed;
                }
                set
                {
                    _WindSpeed = value;
                }
            }
    
            public sbyte WindDirectionX
            {
                get
                {
                    return _WindDirectionX;
                }
                set
                {
                    _WindDirectionX = value;
                }
            }
    
            public sbyte WindDirectionY
            {
                get
                {
                    return _WindDirectionY;
                }
                set
                {
                    _WindDirectionY = value;
                }
            }
    
            // Participanst stats info
            public double[,] ParticipantStatsInfo
            {
                get
                {
                    return _ParticipantStatsInfo;
                }
                set
                {
                    _ParticipantStatsInfo = value;
                }
            }
    
        }
    }
    Then this is my program.cs file:

    Code:
    using PcarsUDP;
    using System;
    using System.Net;
    using System.Net.Sockets;
    using System.IO;
    using WiringPi;
    using System.Threading;
    using System.Data;
    using System.Windows.Forms;
    
    
    namespace UDP_Example
    {
        class Program
        {
            //Define LED pin
            const int PitPin = 18; //Physical pin 18
            const int WaterPin = 16;
            const int OilPin = 12;
            const int DamagePin = 10;
            const int RGBBluePin = 40; //Physical pin 40 = GPIO 16
            const int RGBGreenPin = 36; //Physical pin 36
            const int RGBRedPin = 38; //Physical pin 38 
            const int FuelPin = 8;
            const int Bar1Pin = 3; //Physical pin 3
            const int Bar2Pin = 5; //Physical pin 5
            const int Bar3Pin = 7; //Physical pin 7
            const int Bar4Pin = 11; //Physical pin 11
            const int Bar5Pin = 13; //Physical pin 13
            const int Bar6Pin = 15; //Physical pin 15
            const int Bar7Pin = 19; //Physical pin 19
            const int Bar8Pin = 21; //Physical pin 21
            const int Bar9Pin = 23; //Physical pin 23
            const int Bar10Pin = 29; //Physical pin 29
    
      
            static void Main(string[] args)
            {
              
    
                UdpClient listener = new UdpClient(5606);                       //Create a UDPClient object
                IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, 5606);       //Start recieving data from any IP listening on port 5606 (port for PCARS2)
    
    
                PCars2_UDP uDP = new PCars2_UDP(listener, groupEP);             //Create an UDP object that will retrieve telemetry values from in game.
    
                // Tell the user that we are attempting to start the GPIO
                Console.WriteLine("Initializing GPIO Interface");
    
                // The WiringPiSetup method is static and returns either true or false
                // Any value less than 0 represents a failure
                if (Init.WiringPiSetupPhys() == 0)
                {
                    Console.WriteLine("GPIO Interface initializing OK");
                }
                else
                {
                    Console.WriteLine("Error when initializing GPIO interface");
                }
                //ensures that it initializes the GPIO interface and reports ready to work. We will use Physical Pin Numbers
    
                // Tell the Pi that we will send data out the GPIO
                GPIO.pinMode(PitPin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(WaterPin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(OilPin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(DamagePin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(RGBGreenPin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(RGBBluePin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(RGBRedPin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(FuelPin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(Bar1Pin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(Bar2Pin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(Bar3Pin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(Bar4Pin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(Bar5Pin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(Bar6Pin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(Bar7Pin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(Bar8Pin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(Bar9Pin, (int)GPIO.GPIOpinmode.Output);
                GPIO.pinMode(Bar10Pin, (int)GPIO.GPIOpinmode.Output);
    
                //Turn all LEDs ON for 1 second
    
                GPIO.digitalWrite(PitPin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(WaterPin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(OilPin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(DamagePin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(FuelPin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(Bar1Pin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(Bar2Pin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(Bar3Pin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(Bar4Pin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(Bar5Pin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(Bar6Pin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(Bar7Pin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(Bar8Pin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(Bar9Pin, (int)GPIO.GPIOpinvalue.High);
                GPIO.digitalWrite(Bar10Pin, (int)GPIO.GPIOpinvalue.High);
                Thread.Sleep(1000);
    
                // Turn all LEDs off
                GPIO.digitalWrite(PitPin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(WaterPin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(OilPin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(DamagePin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(FuelPin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(Bar1Pin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(Bar2Pin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(Bar3Pin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(Bar4Pin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(Bar5Pin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(Bar6Pin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(Bar7Pin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(Bar8Pin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(Bar9Pin, (int)GPIO.GPIOpinvalue.Low);
                GPIO.digitalWrite(Bar10Pin, (int)GPIO.GPIOpinvalue.Low);
    
                // Tell the user that GPIO Initialization Completed successfully
                //Console.WriteLine("GPIO Initialization Complete");
    
                
                Console.WriteLine("wait for udp");
    
                // Test writing a text file to path
                //string path = @"MyTest.txt";
                //if (!File.Exists(path))
                // {
                // Create a file to write to.
                // using (StreamWriter sw = File.CreateText(path))
                // {
                //   sw.WriteLine("Thankyou");
                //   sw.WriteLine("And");
                //   sw.WriteLine("Comeagain");
                // }
                //}
    
                // Define variables
    
                int FuelLED = 0;
                int OldFuelLED = 0;
                int SuspDamage = 0;
                string[] TireNameArray = { "Front Left", "Front Right", "Rear Left", "Rear Right" };
                float BBfloat = 0.0F;  // Can't understand the Brake Bias value
    
                // These values are counteres, for slowing down the printing to console. Each loop increases values by 1. 
                // When counter is high enough, the program prints UDP value to console and resets counter.
                int BBshown = 0;
                int speedcount = 800;
                int tbpShown = 0;
                int OdometerShown = 0;
                int gngShown = 300;
                int npShown = 1350;
                int staShown = 0;
                int piShown = 900;
                int owShown = 900;
                int ttShown = 0;
                int trtShown = 500;
                int ambShown = 300;
                int rainShown = 1400;
                int ChequeredFlag = 0;
                int PitShown = 0;
    
    
    
                while (true)
                {
                    uDP.readPackets();                     //Read Packets ever loop iteration
    
                        /* Participant info */
                        
            piShown++;
                        if (piShown >= 100)
                        {
                            // Current total time
                            double CurrentTotalTime = (uDP.ParticipantInfo[uDP.ViewedParticipantIndex, 14]) / 60;
                            var timeSpanTotalTime = TimeSpan.FromMinutes(CurrentTotalTime);
                            int hh1 = timeSpanTotalTime.Hours;
                            int mm1 = timeSpanTotalTime.Minutes;
                            int ss1 = timeSpanTotalTime.Seconds;
                            int ms1 = timeSpanTotalTime.Milliseconds;
                            Console.WriteLine("Current lap time: {0:00}:{1:00}:{2:00}:{3:000}", hh1, mm1, ss1, ms1); //Number of digits after colon sets number of digits displayed
    
                            //Current sector time
                            double CurrentSectorTime = (uDP.ParticipantInfo[uDP.ViewedParticipantIndex, 15]) / 60;
                            var timeSpanCurrentSector = TimeSpan.FromMinutes(CurrentSectorTime);
                            int hh2 = timeSpanCurrentSector.Hours;
                            int mm2 = timeSpanCurrentSector.Minutes;
                            int ss2 = timeSpanCurrentSector.Seconds;
                            int ms2 = timeSpanCurrentSector.Milliseconds;
                            Console.WriteLine("Current sector time: {0:00}:{1:00}:{2:00}:{3:000}", hh2, mm2, ss2, ms2);
    
                        // Current world record lap time
                        //float WorldFastestLapTime = (uDP.WorldFastestLapTime / 60);
                        //var timeSpanWRLapTime = TimeSpan.FromMinutes(WorldFastestLapTime);
                        //int hh4 = timeSpanWRLapTime.Hours;
                        //int mm4 = timeSpanWRLapTime.Minutes;
                        //int ss4 = timeSpanWRLapTime.Seconds;
                        //int ms4 = timeSpanWRLapTime.Milliseconds;
                        //Console.WriteLine("Current World Record: {0:00}:{1:00}:{2:00}:{3:000}", hh4, mm4, ss4, ms4);
    
                        // Race position
                        double RacePosition = (uDP.ParticipantInfo[uDP.ViewedParticipantIndex, 7]); //Get race position
                            int RaceParticipants = uDP.NumberParticipants; //Get number of participants
                            Console.WriteLine("Position: " + RacePosition + " out of " + RaceParticipants);
    
                            //Current sector
                            double CurrentSector = (uDP.ParticipantInfo[uDP.ViewedParticipantIndex, 8]);
                            Console.WriteLine("Current sector is: " + CurrentSector);
    
                        //Current time
                        double CurrentTime = (uDP.ParticipantInfo[uDP.ViewedParticipantIndex, 14]);
                        Console.WriteLine("Current time is: " + CurrentTime);
    
                       
    
                        //Track Location
                        //Console.WriteLine("Track is " + uDP.TrackLocation);
                        //Console.WriteLine("Variation: " + uDP.TrackVariation);
    
                        // Current Lap
                        double CurrentLap = (uDP.ParticipantInfo[uDP.ViewedParticipantIndex, 13]);
                            Console.WriteLine("Current lap number is: " + CurrentLap);
                        
                     
    
                        // Fastest lap time
                        double FastestLapTime = (uDP.ParticipantStatsInfo[uDP.ViewedParticipantIndex,1]) / 60;
                            var timeSpanFLLapTime = TimeSpan.FromMinutes(FastestLapTime);
                            int hh6 = timeSpanFLLapTime.Hours;
                            int mm6 = timeSpanFLLapTime.Minutes;
                            int ss6 = timeSpanFLLapTime.Seconds;
                            int ms6 = timeSpanFLLapTime.Milliseconds;
                            Console.WriteLine("Fastest Lap Time: {0:00}:{1:00}:{2:00}:{3:000}", hh6, mm6, ss6, ms6);
                       
    
    
    
                            // Last lap time
                            double LastLapTime = (uDP.ParticipantStatsInfo[uDP.ViewedParticipantIndex, 2]) / 60;
                            var timeSpanLLLapTime = TimeSpan.FromMinutes(LastLapTime);
                            int hh7 = timeSpanLLLapTime.Hours;
                            int mm7 = timeSpanLLLapTime.Minutes;
                            int ss7 = timeSpanLLLapTime.Seconds;
                            int ms7 = timeSpanLLLapTime.Milliseconds;
                            Console.WriteLine("Last Lap Time: {0:00}:{1:00}:{2:00}:{3:000}", hh7, mm7, ss7, ms7);
    
                            // Wind speed
                            Console.WriteLine("Wind speed is " + uDP.WindSpeed);
    
                        // Car index
                        double CarIndex = (uDP.ParticipantInfo[uDP.ViewedParticipantIndex, 11]);
                        Console.WriteLine("CarIndex is " + CarIndex);
    
                        // RaceState
                        double RaceState = (uDP.ParticipantInfo[uDP.ViewedParticipantIndex, 12]);
                        Console.WriteLine("RaceState is " + RaceState);
    
                        //Event time left
                        float EventTimeRemaining = uDP.EventTimeRemaining;
                        Console.WriteLine("Event time remaining is " + EventTimeRemaining);
    
                        // LapDistance
                        double LapDistance = (uDP.ParticipantInfo[uDP.ViewedParticipantIndex, 6]);
                        Console.WriteLine("Lap distance is " + LapDistance);
    
                        piShown = 0;
    
                        }
    
                    ////************************
                    //// Pit mode schedule
                    ////************************
                    double PitModeSchedule = (uDP.ParticipantInfo[uDP.ViewedParticipantIndex, 10]);
                    if (PitShown < 250)
                    {
                        if (PitModeSchedule == 0)
                        {
                            //Console.WriteLine("No pit requested");
                            GPIO.digitalWrite(PitPin, (int)GPIO.GPIOpinvalue.Low); //Turn Pit led off
                        }
                        else if (PitModeSchedule != 0)
                        {
                            //Console.WriteLine("Pit requested");
                            GPIO.digitalWrite(PitPin, (int)GPIO.GPIOpinvalue.High); //Turn Pit led on
                        }
                        PitShown = 0;
                    }
                    //*****************************
                    // Flag colours
                    //*****************************
                    double HighestFlag = (uDP.ParticipantInfo[uDP.ViewedParticipantIndex, 9]);
                    //Console.WriteLine(HighestFlag);
    
    
                    if (HighestFlag == 1)
                    {
                        //Console.WriteLine("Green flag, go go go!");
                        GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.Low); //Turn on green LED
                        GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.Low);
                    }
                    else if (HighestFlag == 2)
                    {
                        //Console.WriteLine("Blue flag, blue flag!");
                        GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.High); //Turn on blue LED
                        GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.Low);
                    }
                    else if (HighestFlag == 3)
                    {
                        //Console.WriteLine("White flag, slow car in area, watch out");
                        GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.High); //Turn on ALL LED = white
                        GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.High);
                    }
                    else if (HighestFlag == 4)
                    {
                        //Console.WriteLine("Final lap, c'mon push!");
                        GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.High); //Turn on ALL LED = white
                        GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.High);
                    }
                    else if (HighestFlag == 5)
                    {
                        //Console.WriteLine("Red flag! Huge pileup ahead.");
                        GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.High); //Turn on red LED
                    }
                    else if (HighestFlag == 6)
                    {
                        //Console.WriteLine("Yellow flag, slow down");
                        GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.Low); //Turn on blue and green LED = yellow
                        GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.High);
                    }
                    else if (HighestFlag == 7)
                    {
                        //Console.WriteLine("Double yellow, watch out");
                        GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.Low); //Turn on blue and green LED = yellow
                        GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.High);
                    }
                    else if (HighestFlag == 8)
                    {
                        //Console.WriteLine("Black and white flag, unsportsmanlike conduct");
                        GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.High); //Turn on blue and green LED = yellow
                        GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.Low);
                    }
                    else if (HighestFlag == 9)
                    {
                        //Console.WriteLine("Black and orange, mechanical failure");
                    }
                    else if (HighestFlag == 10)
                    {
                        //Console.WriteLine("Black flag, disqualified!");
                    }
                    else if (HighestFlag == 11)
                    {
                        Console.WriteLine("Chequered flag!");
                        if (ChequeredFlag == 0)
                        {
                            GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.Low); //Turn off all LED 
                            GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.Low);
                            GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.Low);
                            Thread.Sleep(250);
                            GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.High); //Turn on ALL LED = white
                            GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.High);
                            GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.High);
                            Thread.Sleep(250);
                            GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.Low); //Turn off all LED 
                            GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.Low);
                            GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.Low);
                            Thread.Sleep(250);
                            GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.High); //Turn on ALL LED = white
                            GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.High);
                            GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.High);
                            Thread.Sleep(250);
                            GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.Low); //Turn off all LED 
                            GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.Low);
                            GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.Low);
                            ChequeredFlag = 1;
                        }
    
                    }
    
                    // If not in race, turn off RGB led
                    //if ((uDP.ParticipantInfo[uDP.ViewedParticipantIndex, 12]) != 2)
                    //{
                    //    GPIO.digitalWrite(RGBBluePin, (int)GPIO.GPIOpinvalue.Low);
                    //    GPIO.digitalWrite(RGBGreenPin, (int)GPIO.GPIOpinvalue.Low);
                    //    GPIO.digitalWrite(RGBRedPin, (int)GPIO.GPIOpinvalue.Low);
                    //}
    
                    /*********************************
                    * GearsNumGears
                    *********************************/
                    gngShown++;
                        if (gngShown > 1000)
                        {
                        string gearhex = uDP.GearNumGears.ToString("X2");
                        char CurrentGear = gearhex[1];
                        char AvailableGears = gearhex[0];
                        Console.WriteLine("Current gear is " + CurrentGear);
                        Console.WriteLine("Total available gear is " + AvailableGears);
                        
                            gngShown = 0;
                        }
    
                        // Track Temperature
                        trtShown++;
                        if (trtShown > 1000)
                        {
                            Console.WriteLine("Track temp is " + uDP.TrackTemperature);
                            trtShown = 0;
                        }
    
                        // Ambient Temperature
                        ambShown++;
                        if (ambShown > 1000)
                        {
                            Console.WriteLine("Ambient temp is " + uDP.AmbientTemperature);
                            ambShown = 0;
                        }
    
                        // Rain Density
                        rainShown++;
                        if (rainShown > 1500)
                        {
                            Console.WriteLine("Rain density is " + uDP.RainDensity);
                            rainShown = 0;
                        }
    
    
                        // Tyre temps
                        ttShown++;
                        if (ttShown > 1200)
                        {
                            for (int i = 0; i < 4; i++)
                            {
    
                                int TTemp = (uDP.TyreTempCenter[i]);
                                Console.WriteLine(TireNameArray[i] + " is " + TTemp + " degrees Celsius");
                                ttShown = 0;
                            }
                        }
    
    
    
                        /*********************************
                        * Speed
                        *********************************/
    
                        var speedkmh = uDP.Speed * 3.6; // Convert speed from m/s to km/h
                        int speed = Convert.ToInt16(speedkmh);
    
    
                        speedcount++;
                        if (speedcount > 1000) // Only show speed at a certain interval
                        {
                            Console.WriteLine("Current speed is " + speed + " km/h");
                            speedcount = 0;
                        }
    
    
                        /************************************
                        * Display tire compound for each tire (this seems to crash the program sometimes, therefor disabled
                        *************************************/
                        //tireShown++;
                        //if (tireShown > 2000)
                        //{
                        //    for (int i = 0; i < 4; i++)
                        //    {
                        //        tireName = System.Text.Encoding.UTF8.GetString(uDP.TyreCompound[i]);
                        //        Console.WriteLine(TireNameArray[i] + " has " + tireName);
                        //        tireShown = 0;
                        //    }
                        //}
    
                        /*************************************
                         * Brake Bias (this is wrong, I can't decode it properly)
                         *************************************/
                        //string bbhex = uDP.BrakeBias.ToString("X2");
                        //Console.WriteLine(bbhex);
                        //string bbfront = ((255 - bbhex) / 2.55);
                        if (BBshown == 0)
                        {
                            Console.WriteLine("Front Brake Bias is " + BBfloat);
                            Console.WriteLine("Rear Brake Bias is " + (100 - BBfloat));
                            BBshown = 1;
                        }
    
                    
    
                        /* NumberParticipants */
                        npShown++;
                        if (npShown > 1500)
                        {
                            Console.WriteLine("Number of participants is " + uDP.NumberParticipants);
                            npShown = 0;
    
                        }
    
    
                        // Split time ahead
                        staShown++;
                        if (staShown > 350)
                        { 
                        float SplitTimeAhead = (uDP.SplitTimeAhead) / 60;
                        var timeSpanSTA = TimeSpan.FromMinutes(SplitTimeAhead);
                        int hh5 = timeSpanSTA.Hours;
                        int mm5 = timeSpanSTA.Minutes;
                        int ss5 = timeSpanSTA.Seconds;
                        int ms5 = timeSpanSTA.Milliseconds;
                        Console.WriteLine("Split time ahead is: {0:00}:{1:00}:{2:00}:{3:000}", hh5, mm5, ss5, ms5);
                        staShown = 0;
                        }
                        /*************************
                        * Turbo Boost Pressure (Can't decode value properly)
                        /************************/
    
                        if (tbpShown == 0)
                        {
                            float tbpf = uDP.TurboBoostPressure;
                            //Console.WriteLine("Gear is " + tbpf);
                            var tbpd = Convert.ToDecimal(tbpf);
                            Console.WriteLine("TurboBoostPressure is " + tbpd);
                            tbpShown = 1;
                        }
    
    
                        /* Odometer in km  */
                        if (OdometerShown == 0)
                        {
                            Console.WriteLine("Odometer is showing " + uDP.OdometerKM + " km");
                            OdometerShown = 1;
                        }
    
    
    
    
                    //For Wheel Arrays 0 = Front Left, 1 = Front Right, 2 = Rear Left, 3 = Rear Right.
                    // Example:
                    // Console.WriteLine(uDP.TyreTempCenter[0]);  //Tyre Temp Center, Front Left Tyre
    
                    /***************************************
                //    *  Water and Oil Temp warnings
                //    ***************************************/
    
                    if (uDP.OilTempCelsius > 103)
                    {
                        // Console.WriteLine("Oil temp is a bit high"); //Change to light LED
                        GPIO.digitalWrite(OilPin, (int)GPIO.GPIOpinvalue.High); //Turn on LED
                    }
                    else { GPIO.digitalWrite(OilPin, (int)GPIO.GPIOpinvalue.Low); } //Turn off OilPin
    
                    if (uDP.WaterTempCelsius > 103)
                    {
                        // Console.WriteLine("Oil and/or water temp is too high"); //Change to light LED
                        GPIO.digitalWrite(WaterPin, (int)GPIO.GPIOpinvalue.High); //Turn on LED
                    }
                    else { GPIO.digitalWrite(WaterPin, (int)GPIO.GPIOpinvalue.Low); } //Turn off OilPin
    
                    // Oil and Water values
                    if (owShown > 200)
                    {
                        Console.WriteLine("Oil temp: " + uDP.OilTempCelsius + " degrees Celsius");
                        Console.WriteLine("Oil pressure: " + uDP.OilPressureKPa + " KPa");
                        Console.WriteLine("Water temp: " + uDP.WaterTempCelsius + " degrees Celsius");
                        Console.WriteLine("Water pressure: " + uDP.WaterPressureKpa + " KPa");
                        owShown = 0;
                    }
    
    
                    /***************************************
                    *  Brake and suspension damage
                    ***************************************/
    
                    byte bytevalue1 = uDP.SuspensionDamage[0];
                        byte bytevalue2 = uDP.SuspensionDamage[1];
                        byte bytevalue3 = uDP.SuspensionDamage[2];
                        byte bytevalue4 = uDP.SuspensionDamage[3];
    
                    //Check suspension damage
                    SuspDamage = 0;
                    for (int i = 0; i < 4; i++)
                            if (uDP.SuspensionDamage[i] > 20) // 0-255. 20 roughly equals 8 in-game
                            {
                                //Console.Write(TireNameArray[i] + "suspension damaged. Value = ");
                                //Console.WriteLine(uDP.SuspensionDamage[0]);
                                SuspDamage++;
                            }
                    if (SuspDamage > 0)
                    {
                        GPIO.digitalWrite(DamagePin, (int)GPIO.GPIOpinvalue.High); //Turn on LED
                    }
                    else
                    {
                        GPIO.digitalWrite(DamagePin, (int)GPIO.GPIOpinvalue.Low); //Turn off LED 
                    }
    
                    /***************************************
                    *  Fuel level meter
                    ***************************************/
                    //Console.WriteLine(uDP.FuelLevel);
                    OldFuelLED = FuelLED;
                    if (uDP.FuelLevel > 0.95)
                    {
                        //Console.WriteLine("Fuel more than 95%"); // Light 10 led on fuel meter
                        FuelLED = 10;
                        GPIO.digitalWrite(Bar1Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar2Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar3Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar4Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar5Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar6Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar7Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar8Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar9Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar10Pin, (int)GPIO.GPIOpinvalue.High);
                    }
                    else if (uDP.FuelLevel > 0.85)
                    {
                        //Console.WriteLine("Fuel more than 85%"); // Light 9 led on fuel meter
                        FuelLED = 9;
                        GPIO.digitalWrite(Bar1Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar2Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar3Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar4Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar5Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar6Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar7Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar8Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar9Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar10Pin, (int)GPIO.GPIOpinvalue.Low);
                    }
                    else if (uDP.FuelLevel > 0.75)
                    {
                        //Console.WriteLine("Fuel more than 75%"); // Light 8 led on fuel meter
                        FuelLED = 8;
                        GPIO.digitalWrite(Bar1Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar2Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar3Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar4Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar5Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar6Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar7Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar8Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar9Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar10Pin, (int)GPIO.GPIOpinvalue.Low);
                    }
                    else if (uDP.FuelLevel > 0.65)
                    {
                        //Console.WriteLine("Fuel more than 65%"); // Light 7 led on fuel meter
                        FuelLED = 7;
                        GPIO.digitalWrite(Bar1Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar2Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar3Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar4Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar5Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar6Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar7Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar8Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar9Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar10Pin, (int)GPIO.GPIOpinvalue.Low);
                    }
                    else if (uDP.FuelLevel > 0.55)
                    {
                        //Console.WriteLine("Fuel more than 55%"); // Light 6 led on fuel meter
                        FuelLED = 6;
                        GPIO.digitalWrite(Bar1Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar2Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar3Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar4Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar5Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar6Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar7Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar8Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar9Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar10Pin, (int)GPIO.GPIOpinvalue.Low);
                    }
                    else if (uDP.FuelLevel > 0.45)
                    {
                        //Console.WriteLine("Fuel more than 45%"); // Light 5 led on fuel meter
                        FuelLED = 5;
                        GPIO.digitalWrite(Bar1Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar2Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar3Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar4Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar5Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar6Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar7Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar8Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar9Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar10Pin, (int)GPIO.GPIOpinvalue.Low);
                    }
                    else if (uDP.FuelLevel > 0.35)
                    {
                        //Console.WriteLine("Fuel more than 35%"); // Light 4 led on fuel meter
                        FuelLED = 4;
                        GPIO.digitalWrite(Bar1Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar2Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar3Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar4Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar5Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar6Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar7Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar8Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar9Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar10Pin, (int)GPIO.GPIOpinvalue.Low);
                    }
                    else if (uDP.FuelLevel > 0.25)
                    {
                        //Console.WriteLine("Fuel more than 25%"); // Light 3 led on fuel meter
                        FuelLED = 3;
                        GPIO.digitalWrite(Bar1Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar2Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar3Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar4Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar5Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar6Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar7Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar8Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar9Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar10Pin, (int)GPIO.GPIOpinvalue.Low);
                    }
                    else if (uDP.FuelLevel > 0.15)
                    {
                        //Console.WriteLine("Fuel more than 15%"); // Light 2 led on fuel meter
                        FuelLED = 2;
                        GPIO.digitalWrite(Bar1Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar2Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar3Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar4Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar5Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar6Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar7Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar8Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar9Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar10Pin, (int)GPIO.GPIOpinvalue.Low);
                    }
                    else if (uDP.FuelLevel > 0.05)
                    {
                        //Console.WriteLine("Fuel more than 5%"); // Light 1 led on fuel meter
                        FuelLED = 1;
                        GPIO.digitalWrite(Bar1Pin, (int)GPIO.GPIOpinvalue.High);
                        GPIO.digitalWrite(Bar2Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar3Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar4Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar5Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar6Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar7Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar8Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar9Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar10Pin, (int)GPIO.GPIOpinvalue.Low);
                    }
                    else if (uDP.FuelLevel < 0.05)
                    {
                        //Console.WriteLine("Fuel less than 5%"); // Light 0 led on fuel meter
                        FuelLED = 0;
                        GPIO.digitalWrite(Bar1Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar2Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar3Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar4Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar5Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar6Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar7Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar8Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar9Pin, (int)GPIO.GPIOpinvalue.Low);
                        GPIO.digitalWrite(Bar10Pin, (int)GPIO.GPIOpinvalue.Low);
                    }
                    //Check if Fuel level has changed
                    if (OldFuelLED != FuelLED)
                        {
                            Console.WriteLine("Fuel level now around " + FuelLED + "0 %");
                        }
                        
                    }
    
    
                }
            }
        }
    Most is working, some are not working, but maybe is of help to someone else. I'm not a programmer, so look at the code at your own risk
    Thrustmaster TX, Italia 458 wheel, 2 pedals, Firmware 54, Xbox One X since Aug -18, 24" 1080 monitor
    Don't miss Yorkie065's excellent videos: Ep26-LiveTrack pt1. Ep 27-LiveTrack pt2.
    The following user likes this Post: SpinnPaget


Similar Threads

  1. Buttonbox
    By Niki Lauda DK in forum Project CARS 2 on XBOX One
    Replies: 114
    Last Post: 01-05-2018, 11:07
  2. PS4 : UDP and buttonbox / keyboard
    By vince34750 in forum Project CARS 2 on Playstation 4
    Replies: 8
    Last Post: 12-10-2017, 21:31
  3. Buttonbox ps4
    By Sanderski in forum Project CARS 2 on Playstation 4
    Replies: 1
    Last Post: 02-10-2017, 12:48
  4. PS4 CLEAN DRIVERS WANTED - USERNAMES WANTED
    By Jimmy Rinser in forum Multiplayer
    Replies: 122
    Last Post: 12-02-2016, 15:23
  5. Buttonbox, wich one to buy?
    By goeiste in forum Project CARS on Playstation 4
    Replies: 20
    Last Post: 08-02-2016, 06:06

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •