📜 ⬆️ ⬇️

Ambilight for World of Tanks - New Year Lights

To start the video. (This is not exactly Ambilight - this is a color indicator of tank health). The video shakes and shakes due to the fact that with one hand I take off, the second I try to play.


In the manufacture of everything came out very simple.

Ingredients Required:

1. Arduino - what is;
2. WS2812B LEDs (I used the ring - I bought it a long time ago, now I decided to use it);
3. Mod for tanks . Mod for my project was written by comrade Kotyarko_O from the forum koreanrandom, for which a special thank you to him. In the archive with the mod source attached;
4. Application for PC. - in the archive source and application in the folder bin.
')
All this does not look very nice, I stuck it to the monitor on double-sided tape.

image

BUT! Minimum details. For the code, please do not judge strictly, it is crooked :) I am a programmer of copy-and-paste :) Who would not like it much, you can remake it beautifully and practically.

Arduino code
#include <Adafruit_NeoPixel.h> #ifdef __AVR__ #include <avr/power.h> #endif #define PIN 6 #define NUMPIXELS 8 Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); String ser; int red = 0; int green =0; void setup() { pixels.begin(); // This initializes the NeoPixel library. Serial.begin(9600); while (!Serial) { ; // wait for port to be ready } Serial.setTimeout(100); } void loop() { if (Serial.available() > 0) { ser = Serial.readString(); if (ser != "end") { green = ser.toInt()*2; red = green-100; for(int i=0;i<NUMPIXELS;i++) { pixels.setPixelColor(i, pixels.Color(red,green,0)); } pixels.show(); } else { for(int i=0;i<NUMPIXELS;i++) { pixels.setPixelColor(i, pixels.Color(0,0,0)); } pixels.show(); } } } 


PC program written in C #

private void button1_Click (object sender, EventArgs e)
{
timer1.Enabled = true;
}

private void timer1_Tick (object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument ();
SerialPort serialPort1 = new SerialPort ();
doc.Load (@ "C: \ World_of_Tanks \ res_mods \ 0.9.17.0.1 \ scripts \ client \ gui \ mods \ mod_ArduinoHP.xml");
string maxHealth = doc.DocumentElement.ChildNodes [0] .InnerText;
string currentHealth = doc.DocumentElement.ChildNodes [1] .InnerText;
string healthProgress = doc.DocumentElement.ChildNodes [2] .InnerText;
serialPort1.PortName = "COM13"; // set the name of the COM port with which the Arduino works
serialPort1.Open (); // open the COM port

if (healthProgress! = "")
{
serialPort1.Write (healthProgress);
}
else
serialPort1.Write ("end");
serialPort1.Close (); // close the COM port
}

Well, that's all, respectively. It works in the simplest way. The mod for tanks adds all the necessary information to the xml file, and the PC application in turn reads xml and transmits all the information to Arduin, which in turn controls the color.

PS All this can be improved, finished, finished, improved ... But I want to sleep already :)

PPS Happy New Year!

Source: https://habr.com/ru/post/400461/


All Articles