玩玩LED点阵屏(arduino nano)

做些记录,特别是led显示左移效果的代码,二进制位的特效函数

unsigned char LedArray1[1][32]=
{
0xff,0xd7,0x83,0xd6,0xc6,0xd4,0xc6,0x82,0xd6,0xba,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x97,0x57,0x81,0x95,0x55,0xd5,0xdf,0xdd,0xe1,0xff,0xff,0xff,0xff,0xff,0xff,
};

const unsigned char LedArray1_hidden[1][32]=
{
0xff,0xd7,0x83,0xd6,0xc6,0xd4,0xc6,0x82,0xd6,0xba,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x97,0x57,0x81,0x95,0x55,0xd5,0xdf,0xdd,0xe1,0xff,0xff,0xff,0xff,0xff,0xff,
};

#define LEDARRAY_D 2
#define LEDARRAY_C 3
#define LEDARRAY_B 4
#define LEDARRAY_A 5
#define LEDARRAY_G 6
#define LEDARRAY_DI 7
#define LEDARRAY_CLK 8
#define LEDARRAY_LAT 9

void led_init(){
        pinMode(LEDARRAY_D, OUTPUT);
        pinMode(LEDARRAY_C, OUTPUT);
        pinMode(LEDARRAY_B, OUTPUT);
        pinMode(LEDARRAY_A, OUTPUT);
        pinMode(LEDARRAY_G, OUTPUT);
        pinMode(LEDARRAY_DI, OUTPUT);
        pinMode(LEDARRAY_CLK, OUTPUT);
        pinMode(LEDARRAY_LAT, OUTPUT);
}

unsigned char led_Display_Buffer[2];

void led_display(const unsigned char dat[][32])
{
    unsigned char i;

    for( i = 0 ; i < 16 ; i++ )
    {
        digitalWrite(LEDARRAY_G, HIGH);        //更新数据时候关闭显示。等更新完数据,打开138显示行。防止重影。

        led_Display_Buffer[0] = dat[0][i];
        led_Display_Buffer[1] = dat[0][i+16];

        led_send(led_Display_Buffer[1]);
        led_send(led_Display_Buffer[0]);

        digitalWrite(LEDARRAY_LAT, HIGH);                    //锁存数据
        delayMicroseconds(1);

        digitalWrite(LEDARRAY_LAT, LOW);
        delayMicroseconds(1);

        led_scan_line(i);                            //选择第i行

        digitalWrite(LEDARRAY_G, LOW);

        delayMicroseconds(100);;            //延时一段时间,让LED亮起来。
    }
}

//****************************************************
//扫描行
//****************************************************
void led_scan_line( unsigned char m)
{
    switch(m)
    {
        case 0:
            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, LOW);
            break;
        case 1:
            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, HIGH);
            break;
        case 2:
            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, LOW);
            break;
        case 3:
            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, HIGH);
            break;
        case 4:
            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, LOW);
            break;
        case 5:
            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, HIGH);
            break;
        case 6:
            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, LOW);
            break;
        case 7:
            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, HIGH);
            break;
        case 8:
            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, LOW);
            break;
        case 9:
            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, HIGH);
            break;
        case 10:
            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, LOW);
            break;
        case 11:
            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, HIGH);
            break;
        case 12:
            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, LOW);
            break;
        case 13:
            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, HIGH);
            break;
        case 14:
            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, LOW);
            break;
        case 15:
            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, HIGH);
            break;
        default : break;
    }
}

//****************************************************
//发送数据
//****************************************************
void led_send( unsigned char dat)
{
    unsigned char i;
    digitalWrite(LEDARRAY_CLK, LOW);
    delayMicroseconds(1);
    digitalWrite(LEDARRAY_LAT, LOW);
    delayMicroseconds(1);

    for( i = 0 ; i < 8 ; i++ )
    {
        if( dat&0x01 )
        {
            digitalWrite(LEDARRAY_DI, HIGH);
        }
        else
        {
            digitalWrite(LEDARRAY_DI, LOW);
        }

        delayMicroseconds(1);
        digitalWrite(LEDARRAY_CLK, HIGH);                //上升沿发送数据
            delayMicroseconds(1);
        digitalWrite(LEDARRAY_CLK, LOW);
            delayMicroseconds(1);
        dat >>= 1;

    }
}
int get_int_bit(unsigned char integer, int position)
{
  switch (position)
  {
    case 1:
      return integer & 0x01;
      break;
    case 2:
      return (integer & 0x02) >> 1;
    case 3:
      return (integer & 0x04) >> 2;
    case 4:
      return (integer & 0x08) >> 3;
    case 5:
      return (integer & 0x10) >> 4;
   case 6:
      return (integer & 0x20) >> 5;
    case 7:
      return (integer & 0x40) >> 6;
    case 8:
      return (integer & 0x80) >> 7;
    default:
      break;
  }
  return 0;
}
int remove_bit_value(unsigned char  value, int position)
{
  int bit = 1 << position-1;
  int nMark = 0;
  nMark = (~nMark) ^ bit;
  value &= nMark;
  return value;
}
int set_bit_value(unsigned char  value, int position)
{
  int pos = 1 << position-1;
  value |= pos;
  return value;
}
int set_int_bit(unsigned char integer, int position, int newValue)
{
  if (newValue > 0)
    return set_bit_value(integer, position);
  else
    return remove_bit_value(integer, position);
}
int led_move_header1[16];
int led_move_header2[16];
void led_move_left(unsigned char word2Move[][32])
{
    //RESET
    for(int i = 0;i < 16;i++)
    {
        led_move_header1[i]=1;
        led_move_header2[i]=1;
    }
    //记录左面LED点阵最左面一排的BIT位
    for(int i = 0;i < 16;i++)
    {
        if(get_int_bit(word2Move[0][i], 8)>0)
          led_move_header1[i]=1;
        else
          led_move_header1[i]=0;
    }
    //记录右面LED点阵最左面一排的BIT位
    for(int i = 16;i < 32;i++)
    {
        if(get_int_bit(word2Move[0][i], 8)>0)
          led_move_header2[i-16]=1;
        else
          led_move_header2[i-16]=0;
    }
    //左面LED点阵BIT位左移
    for(int i = 0;i < 16;i++)
        word2Move[0][i]=word2Move[0][i]<<1;
    //右面LED点阵BIT位左移
    for(int i = 16;i < 32;i++)
        word2Move[0][i]=word2Move[0][i]<<1;
    //将LED点阵最左面一排的BIT位SET到最右面一排BIT位
    for(int i = 0;i < 16;i++)
        word2Move[0][i]=set_int_bit(word2Move[0][i], 1, led_move_header2[i]);
    //将LED点阵最左面一排的BIT位SET到最右面一排BIT位
    for(int i = 16;i < 32;i++)
        word2Move[0][i]=set_int_bit(word2Move[0][i], 1, led_move_header1[i-16]);
}

void setup(){
  led_init();
}

void loop(){
  for(int led_display_delay=0;led_display_delay<100;led_display_delay++)
  {
       led_display(LedArray1);
  }
      led_move_left(LedArray1);

}

LED屏:https://item.taobao.com/item.htm?id=16401785016&_u=iq9aqj2141

arduino连接图

mixly代码:

~/MixlyControls.xml

<!--
type="company"
block="block/MixlyControls.js"
generator="generator/MixlyControls.js"
media="media/MixlyControls"
language="language/MixlyControls"
-->
<script type="text/javascript" src="../../blocks/company/MixlyControls.js"></script>
<script type="text/javascript" src="../../generators/arduino/company/MixlyControls.js"></script>
<category id="McKay_LED_LCD" name="McKay-LED点阵屏" colour="20">
    <block type="LED_Init">
    </block>
    <block type="LED_Display">
        <value name="content"></value>
        <value name="delay"></value>
    </block>
    <block type="LED_LeftMove">
        <value name="varName"></value>
    </block>
    <block type="LED_ClearDisplay">
    </block>
    <block type="LED_ContentArrayRef">
        <value name="reference"></value>
    </block>
    <block type="LED_Content">
        <value name="a1-1"></value>
        <value name="a1-2"></value>
        <value name="a1-3"></value>
        <value name="a1-4"></value>
        <value name="a1-5"></value>
        <value name="a1-6"></value>
        <value name="a1-7"></value>
        <value name="a1-8"></value>
        <value name="a1-9"></value>
        <value name="a1-10"></value>
        <value name="a1-11"></value>
        <value name="a1-12"></value>
        <value name="a1-13"></value>
        <value name="a1-14"></value>
        <value name="a1-15"></value>
        <value name="a1-16"></value>

        <value name="a2-1"></value>
        <value name="a2-2"></value>
        <value name="a2-3"></value>
        <value name="a2-4"></value>
        <value name="a2-5"></value>
        <value name="a2-6"></value>
        <value name="a2-7"></value>
        <value name="a2-8"></value>
        <value name="a2-9"></value>
        <value name="a2-10"></value>
        <value name="a2-11"></value>
        <value name="a2-12"></value>
        <value name="a2-13"></value>
        <value name="a2-14"></value>
        <value name="a2-15"></value>
        <value name="a2-16"></value>

        <value name="a3-1"></value>
        <value name="a3-2"></value>
        <value name="a3-3"></value>
        <value name="a3-4"></value>
        <value name="a3-5"></value>
        <value name="a3-6"></value>
        <value name="a3-7"></value>
        <value name="a3-8"></value>
        <value name="a3-9"></value>
        <value name="a3-10"></value>
        <value name="a3-11"></value>
        <value name="a3-12"></value>
        <value name="a3-13"></value>
        <value name="a3-14"></value>
        <value name="a3-15"></value>
        <value name="a3-16"></value>

        <value name="a4-1"></value>
        <value name="a4-2"></value>
        <value name="a4-3"></value>
        <value name="a4-4"></value>
        <value name="a4-5"></value>
        <value name="a4-6"></value>
        <value name="a4-7"></value>
        <value name="a4-8"></value>
        <value name="a4-9"></value>
        <value name="a4-10"></value>
        <value name="a4-11"></value>
        <value name="a4-12"></value>
        <value name="a4-13"></value>
        <value name="a4-14"></value>
        <value name="a4-15"></value>
        <value name="a4-16"></value>

        <value name="a5-1"></value>
        <value name="a5-2"></value>
        <value name="a5-3"></value>
        <value name="a5-4"></value>
        <value name="a5-5"></value>
        <value name="a5-6"></value>
        <value name="a5-7"></value>
        <value name="a5-8"></value>
        <value name="a5-9"></value>
        <value name="a5-10"></value>
        <value name="a5-11"></value>
        <value name="a5-12"></value>
        <value name="a5-13"></value>
        <value name="a5-14"></value>
        <value name="a5-15"></value>
        <value name="a5-16"></value>

        <value name="a6-1"></value>
        <value name="a6-2"></value>
        <value name="a6-3"></value>
        <value name="a6-4"></value>
        <value name="a6-5"></value>
        <value name="a6-6"></value>
        <value name="a6-7"></value>
        <value name="a6-8"></value>
        <value name="a6-9"></value>
        <value name="a6-10"></value>
        <value name="a6-11"></value>
        <value name="a6-12"></value>
        <value name="a6-13"></value>
        <value name="a6-14"></value>
        <value name="a6-15"></value>
        <value name="a6-16"></value>

        <value name="a7-1"></value>
        <value name="a7-2"></value>
        <value name="a7-3"></value>
        <value name="a7-4"></value>
        <value name="a7-5"></value>
        <value name="a7-6"></value>
        <value name="a7-7"></value>
        <value name="a7-8"></value>
        <value name="a7-9"></value>
        <value name="a7-10"></value>
        <value name="a7-11"></value>
        <value name="a7-12"></value>
        <value name="a7-13"></value>
        <value name="a7-14"></value>
        <value name="a7-15"></value>
        <value name="a7-16"></value>

        <value name="a8-1"></value>
        <value name="a8-2"></value>
        <value name="a8-3"></value>
        <value name="a8-4"></value>
        <value name="a8-5"></value>
        <value name="a8-6"></value>
        <value name="a8-7"></value>
        <value name="a8-8"></value>
        <value name="a8-9"></value>
        <value name="a8-10"></value>
        <value name="a8-11"></value>
        <value name="a8-12"></value>
        <value name="a8-13"></value>
        <value name="a8-14"></value>
        <value name="a8-15"></value>
        <value name="a8-16"></value>

        <value name="a9-1"></value>
        <value name="a9-2"></value>
        <value name="a9-3"></value>
        <value name="a9-4"></value>
        <value name="a9-5"></value>
        <value name="a9-6"></value>
        <value name="a9-7"></value>
        <value name="a9-8"></value>
        <value name="a9-9"></value>
        <value name="a9-10"></value>
        <value name="a9-11"></value>
        <value name="a9-12"></value>
        <value name="a9-13"></value>
        <value name="a9-14"></value>
        <value name="a9-15"></value>
        <value name="a9-16"></value>

        <value name="a10-1"></value>
        <value name="a10-2"></value>
        <value name="a10-3"></value>
        <value name="a10-4"></value>
        <value name="a10-5"></value>
        <value name="a10-6"></value>
        <value name="a10-7"></value>
        <value name="a10-8"></value>
        <value name="a10-9"></value>
        <value name="a10-10"></value>
        <value name="a10-11"></value>
        <value name="a10-12"></value>
        <value name="a10-13"></value>
        <value name="a10-14"></value>
        <value name="a10-15"></value>
        <value name="a10-16"></value>

        <value name="a11-1"></value>
        <value name="a11-2"></value>
        <value name="a11-3"></value>
        <value name="a11-4"></value>
        <value name="a11-5"></value>
        <value name="a11-6"></value>
        <value name="a11-7"></value>
        <value name="a11-8"></value>
        <value name="a11-9"></value>
        <value name="a11-10"></value>
        <value name="a11-11"></value>
        <value name="a11-12"></value>
        <value name="a11-13"></value>
        <value name="a11-14"></value>
        <value name="a11-15"></value>
        <value name="a11-16"></value>

        <value name="a12-1"></value>
        <value name="a12-2"></value>
        <value name="a12-3"></value>
        <value name="a12-4"></value>
        <value name="a12-5"></value>
        <value name="a12-6"></value>
        <value name="a12-7"></value>
        <value name="a12-8"></value>
        <value name="a12-9"></value>
        <value name="a12-10"></value>
        <value name="a12-11"></value>
        <value name="a12-12"></value>
        <value name="a12-13"></value>
        <value name="a12-14"></value>
        <value name="a12-15"></value>
        <value name="a12-16"></value>

        <value name="a13-1"></value>
        <value name="a13-2"></value>
        <value name="a13-3"></value>
        <value name="a13-4"></value>
        <value name="a13-5"></value>
        <value name="a13-6"></value>
        <value name="a13-7"></value>
        <value name="a13-8"></value>
        <value name="a13-9"></value>
        <value name="a13-10"></value>
        <value name="a13-11"></value>
        <value name="a13-12"></value>
        <value name="a13-13"></value>
        <value name="a13-14"></value>
        <value name="a13-15"></value>
        <value name="a13-16"></value>

        <value name="a14-1"></value>
        <value name="a14-2"></value>
        <value name="a14-3"></value>
        <value name="a14-4"></value>
        <value name="a14-5"></value>
        <value name="a14-6"></value>
        <value name="a14-7"></value>
        <value name="a14-8"></value>
        <value name="a14-9"></value>
        <value name="a14-10"></value>
        <value name="a14-11"></value>
        <value name="a14-12"></value>
        <value name="a14-13"></value>
        <value name="a14-14"></value>
        <value name="a14-15"></value>
        <value name="a14-16"></value>

        <value name="a15-1"></value>
        <value name="a15-2"></value>
        <value name="a15-3"></value>
        <value name="a15-4"></value>
        <value name="a15-5"></value>
        <value name="a15-6"></value>
        <value name="a15-7"></value>
        <value name="a15-8"></value>
        <value name="a15-9"></value>
        <value name="a15-10"></value>
        <value name="a15-11"></value>
        <value name="a15-12"></value>
        <value name="a15-13"></value>
        <value name="a15-14"></value>
        <value name="a15-15"></value>
        <value name="a15-16"></value>

        <value name="a16-1"></value>
        <value name="a16-2"></value>
        <value name="a16-3"></value>
        <value name="a16-4"></value>
        <value name="a16-5"></value>
        <value name="a16-6"></value>
        <value name="a16-7"></value>
        <value name="a16-8"></value>
        <value name="a16-9"></value>
        <value name="a16-10"></value>
        <value name="a16-11"></value>
        <value name="a16-12"></value>
        <value name="a16-13"></value>
        <value name="a16-14"></value>
        <value name="a16-15"></value>
        <value name="a16-16"></value>
    </block>
</category>

~/block/MixlyControls.js

‘use strict‘;

goog.provide(‘Blockly.Blocks.MixlyControls‘);

goog.require(‘Blockly.Blocks‘);

//
//Blockly.Blocks.ServoDriveBoard_Init={
//init:function(){
//    this.appendDummyInput("")
//          .appendField("初始化舵机");
//        this.appendValueInput("MinAngle").setCheck(Number).appendField("最小角度");
//        this.appendValueInput("MaxAngle").setCheck(Number).appendField("最大角度");
//
//        this.setColour(20);
//        this.setPreviousStatement(true);
//        this.setNextStatement(true);
//        this.setInputsInline(false);
//        this.setTooltip("初始化舵机");
//  }
//};

Blockly.Blocks.LED_Init={
    init:function(){
            this.setColour(Blockly.Blocks.display.HUE);
            this.appendDummyInput("").appendField("LED初始化");

            this.setPreviousStatement(true);
            this.setNextStatement(true);
            this.setInputsInline(false);
            this.setTooltip("LED初始化");
    }
};

Blockly.Blocks.LED_Display={
    init:function(){
            this.setColour(Blockly.Blocks.display.HUE);
            this.appendValueInput(‘content‘).setAlign(Blockly.ALIGN_RIGHT).appendField("LED显示");
            this.appendValueInput("delay").setCheck(Number).appendField("延时");

            this.setPreviousStatement(true);
            this.setNextStatement(true);
            this.setInputsInline(true);
            this.setTooltip("LED显示");
    }
};

Blockly.Blocks.LED_LeftMove={
    init:function(){
            this.setColour(Blockly.Blocks.display.HUE);
            this.appendDummyInput("").appendField("LED左移");
            this.appendValueInput("varName").appendField("变量名");

            this.setPreviousStatement(true);
            this.setNextStatement(true);
            this.setInputsInline(true);
            this.setTooltip("LED左移");
    }
};

Blockly.Blocks.LED_ClearDisplay={
    init:function(){
            this.setColour(Blockly.Blocks.display.HUE);
            this.appendDummyInput("").appendField("LED清屏");

            this.setPreviousStatement(true);
            this.setNextStatement(true);
            this.setInputsInline(true);
            this.setTooltip("LED清屏");
    }
};

Blockly.Blocks.LED_Content={
    init:function(){
            this.setColour(Blockly.Blocks.display.HUE);
            this.appendDummyInput("").appendField(Blockly.MIXLY_DISPLAY_MATRIX_ARRAYVAR).appendField(new Blockly.FieldTextInput("LedArray1"), "VAR");
            for(var i=1;i<=16;i++)
            {
                var start_block=this.appendDummyInput("");
                for(var j=1;j<=16;j++)
                    start_block.appendField(new Blockly.FieldCheckbox("FALSE"), "a"+i+"-"+j);
            }

            this.setOutput(true, String);
    }
};

Blockly.Blocks.LED_ContentArrayRef={
    init:function(){
            this.setColour(Blockly.Blocks.display.HUE);
            this.appendDummyInput("").appendField(Blockly.MIXLY_DISPLAY_MATRIX_ARRAYVAR).appendField(new Blockly.FieldTextInput("LedArray1"), "reference");

            this.setOutput(true, String);
    }
};

~/generator/MixlyControls.js

‘use strict‘;

goog.provide(‘Blockly.Arduino.MixlyControls‘);

goog.require(‘Blockly.Arduino‘);

//
//Blockly.McKay_ServoDriveBoard_MinAngle=0;
//Blockly.McKay_ServoDriveBoard_MaxAngle=0;
//Blockly.Arduino.ServoDriveBoard_Init=function(){
//    var MinAngle = Blockly.Arduino.valueToCode(this, ‘MinAngle‘, Blockly.Arduino.ORDER_ATOMIC) || ‘0‘;
//    var MaxAngle = Blockly.Arduino.valueToCode(this, ‘MaxAngle‘, Blockly.Arduino.ORDER_ATOMIC) || ‘112‘;
//
//    Blockly.McKay_ServoDriveBoard_MinAngle=parseInt(MinAngle);
//    Blockly.McKay_ServoDriveBoard_MaxAngle=parseInt(MaxAngle);
//
//    Blockly.Arduino.definitions_["define_McKay_ServoDriveBoard_Include"] = "#include <Adafruit_PWMServoDriver.h>\n";
//
//    var defines="#define SERVOMIN 200\n";
//    defines+="#define SERVOMAX 540\n";
//    defines+="#define SERVOMIN_Angle "+Blockly.McKay_ServoDriveBoard_MinAngle+"\n";
//    defines+="#define SERVOMAX_Angle "+Blockly.McKay_ServoDriveBoard_MaxAngle+"\n";
//
//    Blockly.Arduino.definitions_["define_McKay_ServoDriveBoard_Defines"] = defines;
//
//    Blockly.Arduino.definitions_["define_McKay_ServoDriveBoard_pwmObj"] = "Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();\n";
//
//
//    var gotoCode="void servo_goto_angle(int pinId, int angle)\n";
//    gotoCode+="{\n";
//    gotoCode+="     int anglePwmValue=map(angle, SERVOMIN_Angle, SERVOMAX_Angle, SERVOMIN, SERVOMAX);\n";
//    gotoCode+="     pwm.setPWM(pinId,0, anglePwmValue);\n";
//    gotoCode+="}\n";
//    Blockly.Arduino.definitions_["define_McKay_ServoDriveBoard_goto_angle"] = gotoCode;
//
//    var initCode="void servo_init()\n";
//    initCode+="{\n";
//    initCode+="     Serial.begin(9600);\n";
//    initCode+="     pwm.begin();\n";
//    initCode+="     pwm.setPWMFreq(60);\n";
//    initCode+="     delay(200);\n";
//    initCode+="}\n";
//    Blockly.Arduino.definitions_["define_McKay_ServoDriveBoard_initCode"] = initCode;
//
//    return "servo_init();\n";
//};
//
//
//
//Blockly.Arduino.ServoDriveBoard_Do=function(){
//    var ServoNumber = Blockly.Arduino.valueToCode(this, ‘ServoNumber‘, Blockly.Arduino.ORDER_ATOMIC) || ‘0‘;
//    var Angle = Blockly.Arduino.valueToCode(this, ‘Angle‘, Blockly.Arduino.ORDER_ATOMIC) || ‘0‘;
//
//  var code="servo_goto_angle("+ServoNumber+", "+Angle+");\n";
//  return code;
//};

Blockly.Arduino.LED_Init=function(){
    var includes="#define LEDARRAY_D 2\n";
    includes+="#define LEDARRAY_C 3\n";
    includes+="#define LEDARRAY_B 4\n";
    includes+="#define LEDARRAY_A 5\n";
    includes+="#define LEDARRAY_G 6\n";
    includes+="#define LEDARRAY_DI 7\n";
    includes+="#define LEDARRAY_CLK 8\n";
    includes+="#define LEDARRAY_LAT 9\n";
    Blockly.Arduino.definitions_["define_MixlyControls_Include"] = includes;

    var setupCode="void led_init(){\n";
    setupCode+="        pinMode(LEDARRAY_D, OUTPUT);\n";
    setupCode+="        pinMode(LEDARRAY_C, OUTPUT);\n";
    setupCode+="        pinMode(LEDARRAY_B, OUTPUT);\n";
    setupCode+="        pinMode(LEDARRAY_A, OUTPUT);\n";
    setupCode+="        pinMode(LEDARRAY_G, OUTPUT);\n";
    setupCode+="        pinMode(LEDARRAY_DI, OUTPUT);\n";
    setupCode+="        pinMode(LEDARRAY_CLK, OUTPUT);\n";
    setupCode+="        pinMode(LEDARRAY_LAT, OUTPUT);\n";
    setupCode+="}\n";
    Blockly.Arduino.definitions_["define_MixlyControls_led_init"] = setupCode;

    Blockly.Arduino.definitions_["define_MixlyControls_led_var_led_display_buffer"] = "unsigned char led_Display_Buffer[2];\n";

    var functionsCode="";
    functionsCode+="void led_display(const unsigned char dat[][32])\n";
    functionsCode+="{\n";
    functionsCode+="    unsigned char i;\n";
    functionsCode+="\n";
    functionsCode+="    for( i = 0 ; i < 16 ; i++ )\n";
    functionsCode+="    {\n";
    functionsCode+="        digitalWrite(LEDARRAY_G, HIGH);        //更新数据时候关闭显示。等更新完数据,打开138显示行。防止重影。\n";
    functionsCode+="\n";
    functionsCode+="        led_Display_Buffer[0] = dat[0][i];\n";
    functionsCode+="        led_Display_Buffer[1] = dat[0][i+16];\n";
    functionsCode+="\n";
    functionsCode+="        led_send(led_Display_Buffer[1]);\n";
    functionsCode+="        led_send(led_Display_Buffer[0]);\n";
    functionsCode+="\n";
    functionsCode+="        digitalWrite(LEDARRAY_LAT, HIGH);                    //锁存数据\n";
    functionsCode+="        delayMicroseconds(1);\n";
    functionsCode+="\n";
    functionsCode+="        digitalWrite(LEDARRAY_LAT, LOW);\n";
    functionsCode+="        delayMicroseconds(1);\n";
    functionsCode+="\n";
    functionsCode+="        led_scan_line(i);                            //选择第i行\n";
    functionsCode+="\n";
    functionsCode+="        digitalWrite(LEDARRAY_G, LOW);\n";
    functionsCode+="\n";
    functionsCode+="        delayMicroseconds(100);;            //延时一段时间,让LED亮起来。\n";
    functionsCode+="    }\n";
    functionsCode+="}\n";
    functionsCode+="\n";
    functionsCode+="//****************************************************\n";
    functionsCode+="//扫描行\n";
    functionsCode+="//****************************************************\n";
    functionsCode+="void led_scan_line( unsigned char m)\n";
    functionsCode+="{\n";
    functionsCode+="    switch(m)\n";
    functionsCode+="    {\n";
    functionsCode+="        case 0:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, LOW);\n";
    functionsCode+="            break;\n";
    functionsCode+="        case 1:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, HIGH);\n";
    functionsCode+="            break;\n";
    functionsCode+="        case 2:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, LOW);\n";
    functionsCode+="            break;\n";
    functionsCode+="        case 3:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, HIGH);\n";
    functionsCode+="            break;\n";
    functionsCode+="        case 4:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, LOW);\n";
    functionsCode+="            break;\n";
    functionsCode+="        case 5:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, HIGH);\n";
    functionsCode+="            break;\n";
    functionsCode+="        case 6:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, LOW);\n";
    functionsCode+="            break;\n";
    functionsCode+="        case 7:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, LOW);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, HIGH);\n";
    functionsCode+="            break;\n";
    functionsCode+="        case 8:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, LOW);\n";
    functionsCode+="            break;\n";
    functionsCode+="        case 9:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, HIGH);\n";
    functionsCode+="            break;\n";
    functionsCode+="        case 10:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, LOW);\n";
    functionsCode+="            break;\n";
    functionsCode+="        case 11:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, LOW);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, HIGH);\n";
    functionsCode+="            break;\n";
    functionsCode+="        case 12:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, LOW);\n";
    functionsCode+="            break;\n";
    functionsCode+="        case 13:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, LOW);digitalWrite(LEDARRAY_A, HIGH);\n";
    functionsCode+="            break;\n";
    functionsCode+="        case 14:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, LOW);\n";
    functionsCode+="            break;\n";
    functionsCode+="        case 15:\n";
    functionsCode+="            digitalWrite(LEDARRAY_D, HIGH);digitalWrite(LEDARRAY_C, HIGH);digitalWrite(LEDARRAY_B, HIGH);digitalWrite(LEDARRAY_A, HIGH);\n";
    functionsCode+="            break;\n";
    functionsCode+="        default : break;\n";
    functionsCode+="    }\n";
    functionsCode+="}\n";
    functionsCode+="\n";
    functionsCode+="//****************************************************\n";
    functionsCode+="//发送数据\n";
    functionsCode+="//****************************************************\n";
    functionsCode+="void led_send( unsigned char dat)\n";
    functionsCode+="{\n";
    functionsCode+="    unsigned char i;\n";
    functionsCode+="    digitalWrite(LEDARRAY_CLK, LOW);\n";
    functionsCode+="    delayMicroseconds(1);\n";
    functionsCode+="    digitalWrite(LEDARRAY_LAT, LOW);\n";
    functionsCode+="    delayMicroseconds(1);\n";
    functionsCode+="\n";
    functionsCode+="    for( i = 0 ; i < 8 ; i++ )\n";
    functionsCode+="    {\n";
    functionsCode+="        if( dat&0x01 )\n";
    functionsCode+="        {\n";
    functionsCode+="            digitalWrite(LEDARRAY_DI, HIGH);\n";
    functionsCode+="        }\n";
    functionsCode+="        else\n";
    functionsCode+="        {\n";
    functionsCode+="            digitalWrite(LEDARRAY_DI, LOW);\n";
    functionsCode+="        }\n";
    functionsCode+="\n";
    functionsCode+="        delayMicroseconds(1);\n";
    functionsCode+="        digitalWrite(LEDARRAY_CLK, HIGH);                //上升沿发送数据\n";
    functionsCode+="            delayMicroseconds(1);\n";
    functionsCode+="        digitalWrite(LEDARRAY_CLK, LOW);\n";
    functionsCode+="            delayMicroseconds(1);\n";
    functionsCode+="        dat >>= 1;\n";
    functionsCode+="\n";
    functionsCode+="    }\n";
    functionsCode+="}\n";
    functionsCode+="int get_int_bit(unsigned char integer, int position)\n";
    functionsCode+="{\n";
    functionsCode+="  switch (position)\n";
    functionsCode+="  {\n";
    functionsCode+="    case 1:\n";
    functionsCode+="      return integer & 0x01;\n";
    functionsCode+="      break;\n";
    functionsCode+="    case 2:\n";
    functionsCode+="      return (integer & 0x02) >> 1;\n";
    functionsCode+="    case 3:\n";
    functionsCode+="      return (integer & 0x04) >> 2;\n";
    functionsCode+="    case 4:\n";
    functionsCode+="      return (integer & 0x08) >> 3;\n";
    functionsCode+="    case 5:\n";
    functionsCode+="      return (integer & 0x10) >> 4;\n";
    functionsCode+="   case 6:\n";
    functionsCode+="      return (integer & 0x20) >> 5;\n";
    functionsCode+="    case 7:\n";
    functionsCode+="      return (integer & 0x40) >> 6;\n";
    functionsCode+="    case 8:\n";
    functionsCode+="      return (integer & 0x80) >> 7;\n";
    functionsCode+="    default:\n";
    functionsCode+="      break;\n";
    functionsCode+="  }\n";
    functionsCode+="  return 0;\n";
    functionsCode+="}\n";
    functionsCode+="int remove_bit_value(unsigned char  value, int position)\n";
    functionsCode+="{\n";
    functionsCode+="  int bit = 1 << position-1;\n";
    functionsCode+="  int nMark = 0;\n";
    functionsCode+="  nMark = (~nMark) ^ bit;\n";
    functionsCode+="  value &= nMark;\n";
    functionsCode+="  return value;\n";
    functionsCode+="}\n";
    functionsCode+="int set_bit_value(unsigned char  value, int position)\n";
    functionsCode+="{\n";
    functionsCode+="  int pos = 1 << position-1;\n";
    functionsCode+="  value |= pos;\n";
    functionsCode+="  return value;\n";
    functionsCode+="}\n";
    functionsCode+="int set_int_bit(unsigned char integer, int position, int newValue)\n";
    functionsCode+="{\n";
    functionsCode+="  if (newValue > 0)\n";
    functionsCode+="    return set_bit_value(integer, position);\n";
    functionsCode+="  else\n";
    functionsCode+="    return remove_bit_value(integer, position);\n";
    functionsCode+="}\n";
    functionsCode+="int led_move_header1[16];\n";
    functionsCode+="int led_move_header2[16];\n";
    functionsCode+="void led_move_left(unsigned char word2Move[][32])\n";
    functionsCode+="{\n";
    functionsCode+="    //RESET\n";
    functionsCode+="    for(int i = 0;i < 16;i++)\n";
    functionsCode+="    {\n";
    functionsCode+="        led_move_header1[i]=1;\n";
    functionsCode+="        led_move_header2[i]=1;\n";
    functionsCode+="    }      \n";
    functionsCode+="    //记录左面LED点阵最左面一排的BIT位\n";
    functionsCode+="    for(int i = 0;i < 16;i++)\n";
    functionsCode+="    {\n";
    functionsCode+="        if(get_int_bit(word2Move[0][i], 8)>0)\n";
    functionsCode+="          led_move_header1[i]=1;\n";
    functionsCode+="        else\n";
    functionsCode+="          led_move_header1[i]=0;\n";
    functionsCode+="    }\n";
    functionsCode+="    //记录右面LED点阵最左面一排的BIT位\n";
    functionsCode+="    for(int i = 16;i < 32;i++)\n";
    functionsCode+="    {\n";
    functionsCode+="        if(get_int_bit(word2Move[0][i], 8)>0)\n";
    functionsCode+="          led_move_header2[i-16]=1;\n";
    functionsCode+="        else\n";
    functionsCode+="          led_move_header2[i-16]=0;\n";
    functionsCode+="    }    \n";
    functionsCode+="    //左面LED点阵BIT位左移\n";
    functionsCode+="    for(int i = 0;i < 16;i++)\n";
    functionsCode+="        word2Move[0][i]=word2Move[0][i]<<1;\n";
    functionsCode+="    //右面LED点阵BIT位左移\n";
    functionsCode+="    for(int i = 16;i < 32;i++)\n";
    functionsCode+="        word2Move[0][i]=word2Move[0][i]<<1;\n";
    functionsCode+="    //将LED点阵最左面一排的BIT位SET到最右面一排BIT位\n";
    functionsCode+="    for(int i = 0;i < 16;i++)\n";
    functionsCode+="        word2Move[0][i]=set_int_bit(word2Move[0][i], 1, led_move_header2[i]);\n";
    functionsCode+="    //将LED点阵最左面一排的BIT位SET到最右面一排BIT位\n";
    functionsCode+="    for(int i = 16;i < 32;i++)\n";
    functionsCode+="        word2Move[0][i]=set_int_bit(word2Move[0][i], 1, led_move_header1[i-16]);\n";
    functionsCode+="}\n";

    Blockly.Arduino.definitions_["define_MixlyControls_functions"] = functionsCode;

    return "led_init();\n";
};

Blockly.Arduino.LED_Display=function(block){
    var varName = this.getInputTargetBlock(‘content‘).getFieldValue(‘VAR‘);
    var delay = this.getInputTargetBlock(‘delay‘);

    var ledArray = new Array();
    for (var i = 1; i <= 16; i++) {
        ledArray[i-1] = new Array();
        for (var j = 1; j <= 16; j++) {
          ledArray[i-1][j-1] = (this.getInputTargetBlock(‘content‘).getFieldValue(‘a‘ + i + ‘-‘ +j) == "TRUE") ? 0 : 1;
        }
    }

    //生成16进制数组
    var code=generateLEDArrayCode(ledArray);
    Blockly.Arduino.definitions_[varName] = "unsigned char " + varName + "[1][32]=\n" + code;
    Blockly.Arduino.definitions_[varName+‘_hidden‘] = "const unsigned char " + varName + "_hidden[1][32]=\n" + code;

    var functionCode="";
    functionCode+="for(int led_display_delay=0;led_display_delay<"+delay+";led_display_delay++)\n";
    functionCode+="{\n";
    functionCode+="     led_display("+varName+");\n";
    functionCode+="}\n";
    return functionCode;
};

Blockly.Arduino.LED_ClearDisplay=function(block){

    var ledArray = new Array();
    for (var i = 1; i <= 16; i++) {
        ledArray[i-1] = new Array();
        for (var j = 1; j <= 16; j++) {
          ledArray[i-1][j-1] = 1;
        }
    }

    //生成16进制数组
    var code=generateLEDArrayCode(ledArray);
    Blockly.Arduino.definitions_[‘led_clear_define‘] = "const unsigned char led_clear_define[1][32]=\n" + code;

    var functionCode="    led_display(led_clear_define);\n";
    return functionCode;
};

Blockly.Arduino.LED_LeftMove=function(block){
    var reference = this.getInputTargetBlock(‘varName‘).getFieldValue(‘reference‘);

    var functionCode="    led_move_left("+reference+");\n";
    return functionCode;
};

Blockly.Arduino.LED_ContentArrayRef=function(block){
    var varName = this.getInputTargetBlock(‘reference‘);

    return varName;
};

function get_led_2_string(array, from, to)
{
    var tmpStr2 = "";
    for (var j = from; j < to; j++) {
      tmpStr2 += array[j];
    }
    return tmpStr2;
}

function get_16_string(str_2)
{
    return (parseInt(str_2, 2)).toString(16);
}

function generateLEDArrayCode(ledArray)
{
    var code="";
    code+="{\n";
    for (var i = 0; i < 16; i++)
    {
        var str1_2=get_led_2_string(ledArray[i], 0, 4);
        var str1_16=get_16_string(str1_2);

        var str2_2=get_led_2_string(ledArray[i], 4, 8);
        var str2_16=get_16_string(str2_2);

        code += ‘0x‘ + str1_16 + str2_16 + ‘,‘;
    }
    for (var i = 0; i < 16; i++)
    {
        var str1_2=get_led_2_string(ledArray[i], 8, 12);
        var str1_16=get_16_string(str1_2);

        var str2_2=get_led_2_string(ledArray[i], 12, 16);
        var str2_16=get_16_string(str2_2);

        code += ‘0x‘ + str1_16 + str2_16 + ‘,‘;
    }
    code+="\n";
    code+="};\n";
    return code;
}

最后,虽然是能显示,也能左移,但是由于没有自带文字库,所以都靠自己画点,麻烦,以后不干这事了,还是买入整体为好,这么太折腾了。

原文地址:https://www.cnblogs.com/aarond/p/10398658.html

时间: 2024-10-03 23:26:52

玩玩LED点阵屏(arduino nano)的相关文章

arduino nano 配合 as32-tll-100串口通信实验 --基础串口通信

Arduino Nano 超小封装的 Arduino开源系统.玩起来挺爽的. 作为最小单片机系统,首先功耗是没得说,很低很低,并且还有休眠模式,采用电池供电非常理想的功耗. 其次,由于社区完整强大,扩展很方便,无论串行并行,编程接口丰富. 再次,价格很感人,RMB:10-20元.依然是首选. AS32-TTL-100是一款基于Semtech原装SX1278射频芯片而开发,工作频段为410-441MHz,功率为100mW直插式串口数传模块.该模块采用LORA扩频传输,接收灵敏度高,功耗低,距离远.

Arduino Nano + WIZ550io = 简易上网

我爱Arduino Nano – 这是一个非常好外形小巧却功能齐全的Arduino Uno.然而.当我去将它连接到互联网,全部的干净利落小巧也消失在大尺寸的以太网盾底下了. 只是,我近期发现了一个更好的,更紧凑的方式给我的nano连接到互联网 – 通过使用WIZnet公司小巧得多(且更廉价)的WIZ550io模块! 假设你想方便连接,你能够找到一个可连接该模块和Arduino Uno的适配器板,但我想保持小巧的子板.通过我的Nano把它们直接连接在一起.然而.假设你没有适配板,你能够利用同样的方

Arduino Nano 读取ADS1100实例

利用Arduino Nano的wire库可以很方便对ADS1100进行设置和读取转换后的数据. /* * Arduino reads ADS1100 I2C 16bit diff ADC */ /* SDA ==> analog 4 PC4 SCL ==> analog 5 PC5 set register: STBY 0 0 SC DR1 DR0 PGA1 PGA0 default 1 0 0 0 1 1 0 0 0x8C i want 1 0 0 0 1 1 0 0 ign 0 0 con

最新 Arduino 驱动 12接口/户外 LED显示屏/LED点阵屏/LED单元板

起因 现有的驱动LED显示屏的资料,比较好的只有这个.但是它驱动的是08接口的室内显示屏,而我要驱动的是12接口的户外显示屏.两种屏幕的区别在于户外屏幕点阵比较稀疏,而且二者的扫描方式,驱动方式都不太一样.我花了一个下午才摸索出了它的使用方式,因此分享给大家,希望大家不必再绕弯路. 材料准备 12接口(户外)LED单元板一块:比如我是从[这里]买的,大家搜索“半户外 LED 单元板”就可以了.我的板是16x32大小. Arduino Uno一块 5V电源一个(比如充电宝.给手机充电的头) 硬件搭

PMS5003ST+Arduino Nano OLED屏显示

整合OLED显示和PMS5003报数 #include <Arduino.h> #include <pms.h> ////////////////////////////////// #include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> ////////////////////////////////////

Arduino nano pc 串口通信

上回书说到(以下省略100字) 说到底还是要自己写一个PC和Arduino 通信的程序,毕竟还是要集成到咱的系统上来. c# 其实本身是有串口通信的类库的 arduino也自带软硬串行通信类库 两个类库一对话,一切就成了. 哦,我用的vb,哈哈哈 Imports System.IO.Ports Public Class Form1 Private WithEvents port As SerialPort Private Sub btnPort_Click(sender As Object, e

基于Proteus仿真的Arduino学习(2)——LED点阵探究A(LED点阵基础)

一.前言: 随着LED的普及,以LED点阵为基础的显示设置层出不穷.例如,公交车的线路提示牌.高速公路的信息提示牌,安装在大楼上的广告屏幕等.下面,我们将由简单到复杂地探索各种LED点阵的使用方法,同样是基于Proteus的arduino仿真,以arduino uno R3为例,包含以下三个实验:LED点阵显示表情.LED点阵跑马灯.回纹灯.具体介绍如下: 二.仿真电路设计: 本次的三个实验用到的电路连接都是相同的,构建一个电路仿真图即可,仿真图如下: 电路图比较简单,只需将arduino最小系

基于Proteus仿真的Arduino学习(1)——Arduino Uno最小系统及LED的简单使用

一.前言:  A.Arduino简介 Arduino是由一个欧洲开发团队于2005年冬季开发.其成员包括Massimo Banzi.David Cuartielles.Tom Igoe.Gianluca Martino.David Mellis和Nicholas Zambetti.据说Auduino开发团队的领袖Massimo Banzi 之前是意大利Ivrea 一家高科技设计学校的老师.他的学生们经常抱怨找不到便宜好用的微控制器.2005年冬天,Massimo Banzi 跟David Cua

【物联网(IoT)开发】使用 Arduino 和 Python在 Bluemix 上开发一个 IoT 应用程序之控制LED灯开关

上篇"[物联网(IoT)开发]Arduino 入门 Hello World(LED闪烁)"只是通过将一段程序烧录到Arduino开发板上控制LEC闪烁,没有任何连网动作,也就是说断开网络提供电源依然还可以工作.本文将介绍如何开发一个应用程序,以便使用适用于物联网 (Internet of Things, IoT) 的技术.我们的应用程序通过串口收集数据,将其存储在一个 Web 服务器上,然后在网页上实时显式结果,并可以在网页上控制LED的开关. 构建一个类似的应用程序的前提条件 对于第