网站开发 jsp加密,不用模板 网站,旅游网页模板素材,随州网站推广哪家好硬件准备
8*8点阵#xff1a;1个
旋钮电位器#xff1a;1个
面包板#xff1a;1块
杜邦线#xff1a;若干 硬件连线 软件程序
//定义引脚
#define xKnob_pin A0 //x轴旋钮的引脚
#define yKnob_pin A1 //y轴旋钮的引脚
const int row_pin[8] { 6, 11, 10, 3, 17, 4…硬件准备
8*8点阵1个
旋钮电位器1个
面包板1块
杜邦线若干 硬件连线 软件程序
//定义引脚
#define xKnob_pin A0 //x轴旋钮的引脚
#define yKnob_pin A1 //y轴旋钮的引脚
const int row_pin[8] { 6, 11, 10, 3, 17, 4, 8, 9 }; // 行引脚对应的数组
const int col_pin[8] { 2, 7, 19, 5, 13, 18, 12, 16 }; // 列引脚对应的数组int pixels[8][8]; // 点阵对应的数组//定义变量
unsigned int x_val -1;//x轴变量
unsigned int y_val -1;//函数声明
void Init();
void display();
void test();void setup() {Serial.begin(9600);for (int thisRow 0; thisRow 8; thisRow) {pinMode(row_pin[thisRow], OUTPUT); //设置行引脚为输出模式digitalWrite(row_pin[thisRow], LOW); //行引脚输出低电平}for (int thisCol 0; thisCol 8; thisCol) {pinMode(col_pin[thisCol], OUTPUT); //设置列引脚为输出模式digitalWrite(col_pin[thisCol], HIGH); //列引脚输出高电平}
}void loop() {Init();display();//test();
}void Init(){for (int thisRow 0; thisRow 8; thisRow) {digitalWrite(row_pin[thisRow], LOW); //行引脚输出低电平}for (int thisCol 0; thisCol 8; thisCol) {digitalWrite(col_pin[thisCol], HIGH); //列引脚输出高电平}
}void display(){//读取旋钮模拟值映射为0~7x_val map(analogRead(xKnob_pin),0,1023,0,7);y_val map(analogRead(yKnob_pin),0,1023,0,7);Serial.print(x );Serial.println(x_val);Serial.print(y );Serial.println(y_val);//根据模拟值决定哪行哪列亮digitalWrite(col_pin[y_val], LOW);digitalWrite(row_pin[x_val], HIGH);
}void test() {for (int thisCol 0; thisCol 8; thisCol) {digitalWrite(col_pin[thisCol], LOW); //列引脚输出低电平for (int thisRow 0; thisRow 8; thisRow) {digitalWrite(row_pin[thisRow], HIGH); delay(500);digitalWrite(row_pin[thisRow], LOW); }digitalWrite(col_pin[thisCol], HIGH); //列引脚输出高电平}
} 产品展示视频 【Arduino24】88点阵 总结
通过本次实验我学会了8*8点阵的使用并复习了旋钮电位器的知识。