*/
#include <Servo.h>
int _ABVAR_1_Distance = 0 ;
int ardublockUltrasonicSensorCodeAutoGeneratedReturnCM(int trigPin, int echoPin);
{
long duration;
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(20);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
duration = duration / 59;
if ((duration < 2) || (duration > 300)) return false;
return duration;
{
int _ABVAR_2_degree = 0 ;
Servo servo_pin_8;
int _ABVAR_3_N = 0 ;
void a();
}
const int numRows = 4;//定义4行
const int numCols = 4;//定义4列
const int debounceTime = 20;//去抖动时间长度
const char keymap[numRows][numCols]= {//键值,可以按需要更改
{ '1','2','3','+' },
{'4','5','6','-' },
{'7','8','9','X' },
{'*','0','#','/' }
}
const int rowPins[numRows] = {7,6,5,4};//设置硬件对应的引脚
const int colPins[numCols] = {11,10,9,8};
//初始化功能
void setup(){
Serial.begin(9600);
for(int row = 0; row < numRows; row++){
pinMode(rowPins[row],INPUT);
digitalWrite(rowPins[row],HIGH);
}
for(int column = 0;column < numCols; column++){
pinMode(colPins[column],OUTPUT);
digitalWrite(colPins[column],HIGH);
}
{
digitalWrite( 4 , LOW );
Serial.begin(9600);
servo_pin_8.attach(8);
}
}
//主循环
void loop() {
// 添加其他的程序,循环运行
char key = getkey();
if(key !=0){
switch( key)
{
case'258':
{
a();
}
void a()
{
_ABVAR_1_Distance = ardublockUltrasonicSensorCodeAutoGeneratedReturnCM( 4 , 7 ) ;
Serial.print("D");
Serial.print(" ");
Serial.print(_ABVAR_1_Distance);
Serial.print(" ");
Serial.println();
delay( 100 );
if (( ( _ABVAR_1_Distance ) <= ( 20 ) ))
{
servo_pin_8.write( _ABVAR_2_degree );
_ABVAR_2_degree = ( _ABVAR_2_degree + _ABVAR_3_N ) ;
delay( 100 );
if (( ( _ABVAR_2_degree ) == ( 90 ) ))
{
_ABVAR_3_N = -10 ;
}
if (( ( _ABVAR_2_degree ) == ( 0 ) ))
{
_ABVAR_3_N = 10 ;
}
}
else
{
servo_pin_8.write( 0 );
}
}
break;
Serial.print("Got key ");//串口打印键值
Serial.println(key);
}
}
//读取键值程序
char getkey(){
char key = 0;
for(int column = 0;column < numCols; column++){
digitalWrite(colPins[column],LOW);
for(int row = 0 ;row < numRows; row++){
if(digitalRead(rowPins[row]) == LOW){ //是否有按键按下
delay(debounceTime);
while(digitalRead(rowPins[row]) == LOW) //等待按键释放
;
key = keymap[row][column];
}
}
digitalWrite(colPins[column],HIGH); //De-active the current column
}
return key;
}
错误信息:
keyboard_4x4.ino:16:1: error: expected unqualified-id before '{' token
编译有误。
#include <Servo.h>
int _ABVAR_1_Distance = 0 ;
int ardublockUltrasonicSensorCodeAutoGeneratedReturnCM(int trigPin, int echoPin);
{
long duration;
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(20);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
duration = duration / 59;
if ((duration < 2) || (duration > 300)) return false;
return duration;
{
int _ABVAR_2_degree = 0 ;
Servo servo_pin_8;
int _ABVAR_3_N = 0 ;
void a();
}
const int numRows = 4;//定义4行
const int numCols = 4;//定义4列
const int debounceTime = 20;//去抖动时间长度
const char keymap[numRows][numCols]= {//键值,可以按需要更改
{ '1','2','3','+' },
{'4','5','6','-' },
{'7','8','9','X' },
{'*','0','#','/' }
}
const int rowPins[numRows] = {7,6,5,4};//设置硬件对应的引脚
const int colPins[numCols] = {11,10,9,8};
//初始化功能
void setup(){
Serial.begin(9600);
for(int row = 0; row < numRows; row++){
pinMode(rowPins[row],INPUT);
digitalWrite(rowPins[row],HIGH);
}
for(int column = 0;column < numCols; column++){
pinMode(colPins[column],OUTPUT);
digitalWrite(colPins[column],HIGH);
}
{
digitalWrite( 4 , LOW );
Serial.begin(9600);
servo_pin_8.attach(8);
}
}
//主循环
void loop() {
// 添加其他的程序,循环运行
char key = getkey();
if(key !=0){
switch( key)
{
case'258':
{
a();
}
void a()
{
_ABVAR_1_Distance = ardublockUltrasonicSensorCodeAutoGeneratedReturnCM( 4 , 7 ) ;
Serial.print("D");
Serial.print(" ");
Serial.print(_ABVAR_1_Distance);
Serial.print(" ");
Serial.println();
delay( 100 );
if (( ( _ABVAR_1_Distance ) <= ( 20 ) ))
{
servo_pin_8.write( _ABVAR_2_degree );
_ABVAR_2_degree = ( _ABVAR_2_degree + _ABVAR_3_N ) ;
delay( 100 );
if (( ( _ABVAR_2_degree ) == ( 90 ) ))
{
_ABVAR_3_N = -10 ;
}
if (( ( _ABVAR_2_degree ) == ( 0 ) ))
{
_ABVAR_3_N = 10 ;
}
}
else
{
servo_pin_8.write( 0 );
}
}
break;
Serial.print("Got key ");//串口打印键值
Serial.println(key);
}
}
//读取键值程序
char getkey(){
char key = 0;
for(int column = 0;column < numCols; column++){
digitalWrite(colPins[column],LOW);
for(int row = 0 ;row < numRows; row++){
if(digitalRead(rowPins[row]) == LOW){ //是否有按键按下
delay(debounceTime);
while(digitalRead(rowPins[row]) == LOW) //等待按键释放
;
key = keymap[row][column];
}
}
digitalWrite(colPins[column],HIGH); //De-active the current column
}
return key;
}
错误信息:
keyboard_4x4.ino:16:1: error: expected unqualified-id before '{' token
编译有误。