develop

My first great Arduino project ;-)

He that’s cool: I finished my first great arduino project: Solar Power measurement ;-)
Ok, it’s a simple project but the learning effect is good. Read the analog signal and display the voltage value on a lcd (LCD4884).
That’s it.

/*
  Here is my simple
 up to 5V Solar Power measurement sketch...
 version 0.1

 use it with your own risk!

 Any suggestions are welcome.
 E-mail: punkerat76 [at] jkarger [dot] de
 */

#include "LCD4884.h"

void setup()
{
  Serial.begin(9600);

  // we measure up to 5V
  analogReference(DEFAULT);

  lcd.LCD_init();
  lcd.LCD_clear();

  lcd.backlight(OFF); //Turn off the backlight

  lcd.LCD_write_string(5, 0, "Solar Power", MENU_NORMAL);
}

/* loop */

void loop()
{
  solar_power();
  delay(900);
}

/* functions */

int analoginput = 5; // our analog pin
int analogamount = 0; // stores incoming value
int old_analogamount = -1;
float voltage = 0; // used to store voltage value
float old_voltage = -1;

void solar_power()
{
  char buffer[100];

  analogamount = analogRead(analoginput);

  if (old_analogamount != analogamount) {
    old_analogamount = analogamount;

    sprintf(buffer,"%5d on A%d", analogamount, analoginput);
    Serial.println(buffer);
    sprintf(buffer,"%5d", analogamount);
    lcd.LCD_write_string(10, 2, buffer, MENU_NORMAL);
    sprintf(buffer,"on A%d", analoginput);
    lcd.LCD_write_string(45, 2, buffer, MENU_NORMAL);

    voltage = analogamount * 5.0 / 1024.0; // in volts
    if (old_voltage != voltage) {
      old_voltage = voltage;

      dtostrf(voltage, 5, 3, buffer);
      Serial.print("voltage on analog input (V): ");
      Serial.println(buffer);
      lcd.LCD_write_string(10, 4, buffer, MENU_NORMAL);
      lcd.LCD_write_string(45, 4, "V", MENU_NORMAL);

      if (voltage > 0.2) {
        // we have enough power, hehe turn the lights on!!!
        lcd.backlight(ON);
      }
      else {
        lcd.backlight(OFF);
      }
    }
  }
}

syntaxhighlighter for wordpress

after a long search i found my prefered syntax highlighter plugin for wordpress.

here is a little list of the most used highlighters that can be found at the internet.

i choose the SyntaxHighlighter Evolved because the plugin does allow XAML code to be added to a post under the language XML and does not let wordpress interpret the <> characters in the added sourcecode.

here is a little example

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options">
  <Grid>
    <TextBlock Text="it works" />
  </Grid>
</Page>

here are the ugly code change that i mean

<page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options">
  <grid>
    <textblock Text="it works" />
  </grid>
</page>

that’s it

automatically generate wpf listview columns

this code generates automatically listview columns for all properties for the given datatype

public class BaseListView : ListView
{
  public BaseListView() {
    ItemsSourceProperty.AddOwner(typeof(BaseListView), new FrameworkPropertyMetadata(null, OnItemsSourcePropertyChanged));
  }

  private static void OnItemsSourcePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) {
    if (e.OldValue != e.NewValue && e.NewValue != null) {
      var lv = (BaseListView)dependencyObject;
      var gridView = new GridView();
      lv.View = gridView;
      gridView.AllowsColumnReorder = true;
      var properties = lv.DataType.GetProperties();
      foreach (var pi in properties) {
        var binding = new Binding {Path = new PropertyPath(pi.Name), Mode = BindingMode.OneWay};
        var gridViewColumn = new GridViewColumn() {Header = pi.Name, DisplayMemberBinding = binding};
        gridView.Columns.Add(gridViewColumn);
      }
    }
  }

  public Type DataType { get; set; }
}

here is the xaml usage

<Grid>
  <local:BaseListView x:Name="listView" DataType="{x:Type DummyType}" ItemsSource="{Binding Mode=OneWay, Path=DummyTypeList}" />
</Grid>

thats it

here is my answer at stackoverflow

.NET DevCon 2011

2009 hat es mit der BASTA geklappt und dieses jahr ist es die .NET DevCon 2011 *freu*
2 tage geballtes wissen in sich aufsaugen und nicht mehr vergessen und abends ein kleines bierchen in der nürnberger altstadt, hach ist das schön :-)

Categories