在16x2 LCD上显示Intel Galileo IP地址

时间:2014-08-22 19:37:46

标签: intel-galileo windowsondevices iot

我正在运行Windows Developer Program for IoT(https://ms-iot.github.io/content/16x2LCD.htm)的16x2 LCD示例。最好的方法是在显示屏上显示和显示Galileo IP地址而不是"您好!"信息?问候。

代码

stdafx.h中

#pragma once

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>
#include "arduino.h"
#include "LiquidCrystal.h" // we need this library for the LCD commands

Main.cpp的

#include "stdafx.h"

int RS = 4;
int ENABLE = 5;
int D0 = 6;
int D1 = 7;
int D2 = 8;
int D3 = 9;
LiquidCrystal lcd = LiquidCrystal(RS, ENABLE, D0, D1, D2, D3); // define our LCD and which pins to use

int _tmain(int argc, _TCHAR* argv [])
{
    return RunArduinoSketch();
}

void setup()
{
    Log(L"LCD Sample\n");

    lcd.begin(16, 2); // need to specify how many columns and rows are in the LCD unit (it calls clear at the end of begin)

    lcd.setCursor(0, 0);
    lcd.print("Hello!");

    lcd.setCursor(0, 1);
    lcd.print(3.14159, 4); // prints a double, the 2nd number is the digits to print after the .
}

void loop()
{
}

2 个答案:

答案 0 :(得分:1)

我会使用Windows API以字符串形式获取IP地址,然后使用lcd.print将字符串打印到LCD。

This MSDN page在解释和展示如何使用Windows API获取IP地址方面做得很好。

答案 1 :(得分:0)

MSDN上的GetAdaptersInfo页面提供了获取IP地址的示例代码。我基本上将以下代码添加到Galileo项目的设置功能中,并在LCD上显示IP地址:

lcd.begin(16, 2); // columns and rows, LCD unit (it calls clear at the end of begin)
lcd.setCursor(0, 0);

lcd.print("IP Address:");

PIP_ADAPTER_INFO    pAdapterInfo = NULL;
PIP_ADAPTER_INFO    pAdapter = NULL;
ULONG               ulOutBufLen = sizeof(IP_ADAPTER_INFO);
DWORD               dwRetVal = 0;

pAdapterInfo = (IP_ADAPTER_INFO *)MALLOC(sizeof(IP_ADAPTER_INFO));
if (pAdapterInfo == NULL) {
    printf("Error allocating memory needed to call GetAdaptersinfo\n");
}

if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
    FREE(pAdapterInfo);
    pAdapterInfo = (IP_ADAPTER_INFO *)MALLOC(ulOutBufLen);
    if (pAdapterInfo == NULL) {
        printf("Error allocating memory needed to call GetAdaptersinfo\n");
    }
}

if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
    pAdapter = pAdapterInfo;
    lcd.setCursor(0, 1);
    lcd.print(pAdapter->IpAddressList.IpAddress.String);
}

我写了一篇博客post,其中展示了我为实现这一目标所采取的方法。希望这会有所帮助。

相关问题