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

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

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

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

  1. 使用Arduino Nano驱动Lora模块

    使用Arduino Nano驱动Lora模块 为什么选用Lora 射频通信芯片有很多种,但是一般在同样功耗下,距离没有Lora远;同等范围下,没有Lora节能. Lora通信只适用于低速率,高延时的场 ...

  2. Arduino Nano + WIZ550io = 简易上网

    我爱Arduino Nano – 这是一个非常好外形小巧却功能齐全的Arduino Uno.然而.当我去将它连接到互联网,全部的干净利落小巧也消失在大尺寸的以太网盾底下了. 只是,我近期发现了一个更好 ...

  3. Arduino Nano 读取ADS1100实例

    利用Arduino Nano的wire库可以很方便对ADS1100进行设置和读取转换后的数据. /* * Arduino reads ADS1100 I2C 16bit diff ADC */ /* ...

  4. Arduino nano的bootloader文件烧录

    1.买了了nano还没用就用 avrisp烧录器给烧了其他程序,仅仅是的avr单片机了:2.将他恢复成Arduino nano吧. 在Arduino软件安装目录中的hardware\arduino中. ...

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

    起因 现有的驱动LED显示屏的资料,比较好的只有这个.但是它驱动的是08接口的室内显示屏,而我要驱动的是12接口的户外显示屏.两种屏幕的区别在于户外屏幕点阵比较稀疏,而且二者的扫描方式,驱动方式都不太 ...

  6. PMS5003ST+Arduino Nano OLED屏显示

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

  7. Arduino Nano与SIM800C 通信

    首先感谢 原文作者:https://blog.csdn.net/weixin_44481398/article/details/86596933#commentBox 找了好久没有找到,使用他的代码一 ...

  8. PMS5003ST+Arduino Nano 串口读取数据

    先上代码: 库文件是在guihub上的大神写的https://github.com/jbanaszczyk,我拿来小改下用以支持5003ST #include <Arduino.h> #i ...

  9. Arduino - Nano针脚分配时需要注意的事项

    0.1为Rx.Tx 针脚,这两个针脚一般作为串口使用,非串口设备尽量不占用该针脚.2.3为中断口,分别对应中断0.中断1,需要中断功能的设备,必须接入此.2-13.A0-A5,共18个针脚,都可以作为 ...

随机推荐

  1. 二、使用docker-compose搭建AspNetCore开发环境

    1 使用docker-compose搭建开发环境 我们的目标很简单:使用docker-compose把若干个docker容器组合起来就成了. 首先使用Nginx代理所有的Web程序,这样只需要在主机上 ...

  2. Linux下编译安装php7.2

    准备工作 所有操作需要在root用户下 安装路径: /usr/local/php 安装PHP 首先要安装如下依赖包 $ yum install -y gcc gcc-c++  make zlib zl ...

  3. 福利:1H1G2M云服务器限时15元/月,买2送1,一年加6个月只要180元

    平时看文章做测试只能用虚拟机的有福了,现在腾迅做活动,1H1G2M的服务器一个月只需要15元,买2送1,最多可以送6个月. 这个比之前1H1G1M10元一月的要好一些 购买地址

  4. Javascript高级编程学习笔记(96)—— WebGL(2) 类型化视图

    类型化视图 类型化视图一般也被认为是一种类型化数组. 因为其元素必须是某种特定的数据类型,类型化视图都继承自 Dataview Int8Array: 表示8位二补整数(即二进制补数) Uint8Arr ...

  5. Linux磁盘管理及LVM讲解(week2_day2)--技术流ken

    硬盘接口 从整体的角度上,硬盘接口分为IDE.SATA.SCSI和SAS四种,IDE接口硬盘多用于家用产品中,也部分应用于服务器,SCSI接口的硬盘则主要应用于服务器市场,而SAS只在高端服务器上,价 ...

  6. docker(3)容器管理命令

    接着上一篇,今天说一下Docker 有关容器的常用命令.算是比较详细了吧. docker run  命令: 注:此命令作用是使用一个镜像运行启动一个容器. 在启动运行的时候 会检查docker 中是否 ...

  7. .net 配置swagger

    第一步: 在nuget.org中查找Swashbuckle并下载 在nuget.org中查找Swagger.net.UI,并下载 第二步: 下载完之后,App_Start多了三个文件 Swagger. ...

  8. Spring入门(一):创建Spring项目

    本篇博客作为Spring入门系列的第一篇博客,不会讲解什么是Spring以及Spring的发展史这些太理论的东西,主要讲解下如何使用IntelliJ IDEA创建第一个Spring项目以及通过一个示例 ...

  9. while死循环导致的内存溢出

    场景:新开发的功能内测,新调用了其它模块的接口,一如既往的点鼠标,计费,但是许久都没有响应页面遮罩一直锁着,最后抛出了以下异常 咋一看这个异常信息,不就是锁表了吗?把锁表进程Kill掉,再来一遍,结果 ...

  10. Apache2配置多域名站点及支持https

    0x00 预备条件 申请SSL证书 建立对应站点目录 开放443端口 0x01 配置sites-available文件 执行 vi /etc/apache2/sites-available/zecoc ...