Cannot get setmode(1) to work in C#, WPF

I cannot seem to find out how to setmode of blinkstick

i am relatively new to programming so don’t be to hard on me as i am sure it is a slight overlook on my behalf :slight_smile:

here is my code and i am simply wanting to set the mode of the blinkstick to inverse or mode 1 as this is what i need for my lights to function correctly.

here is my code ------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BlinkStickDotNet;

namespace WpfApplication2
{
///


/// Interaction logic for MainWindow.xaml
///

public partial class MainWindow : Window
{
string yourcolor = “#000000”;

    public MainWindow()
    {
        InitializeComponent(); 

        BlinkStick.Hid.AbstractBlinkstickHid[] newhid = BlinkStick.Hid.BlinkstickDeviceFinder.FindDevices();

        foreach (BlinkStick.Hid.AbstractBlinkstickHid found in newhid)
        {
            listBox1.Items.Add(found.Serial.ToString());
        }
        
    }

    private void button_Click(object sender, RoutedEventArgs e)
    {
        
        changecolor(yourcolor);

    }

    private void changecolor(string hexcolor)
    {
        BlinkStick.Hid.AbstractBlinkstickHid[] newhid = BlinkStick.Hid.BlinkstickDeviceFinder.FindDevices();            
       

        foreach (BlinkStick.Hid.AbstractBlinkstickHid found in newhid)
        {               
            found.OpenDevice();
            found.SetLedColor(hexcolor);
            found.CloseDevice();
        }
    }

    private void button_Click_1(object sender, RoutedEventArgs e)
    {
        changecolor("#FFFFFF");//this is inverted normally this is white but in our case this is black and turns off lights
    }

    private void textBox_TextChanged(object sender, TextChangedEventArgs e)// text box named "inputtext"
    {
        yourcolor = inputtext.Text;
    }
    
}

}

any help would be appreciated thank you .

Welcome Bryan!

Your code looks a bit weird to me. I would recommend to take a tour through the wiki:

There are a lot examples.

In the end it is nothing more than this (see the short example code on https://www.blinkstick.com/):

using BlinkStickDotNet;

BlinkStick led = BlinkStick.FindFirst();

led.OpenDevice();
led.SetColor ("red");
led.Blink ("blue");

Edit:

Sorry, but I´ve seen there is no setmode example in the wiki…

Regarding to the short example above it is just:

led.SetMode(1);

Haha, this code looks somewhat familiar!

Anyway, it’s from before I knew of any .NET documentation, and is of my exploration. So it won’t work like arvydas’s.

As for inverting/ setmode:

I do see it in the Wiki p0ke referenced:

public void SetMode(byte mode)
    {
        if (connectedToDriver)
        {
            SetFeature(new byte[2] {4, mode});
        }
    }

Hey Bryan.Im not right at my PC at the moment but I will send a small project with example code later

Here is a small example project. When pressing the button, it sets the mode to 1 and play the colors red, blue, green, yellow. It is just to show how simple it is to use Arvys BlinkStick API.

https://dl.dropboxusercontent.com/u/19452479/ColorModeExample.zip