对于Arduino,可以用
void(* resetFunc)(void) = 0;
......
resetFunc();
进行软复位。
但是,本人的UNO进行过这一操作后出现异常复位的现象。
laser.h如下:
#include "Arduino.h"
#include <RobotIRremote.h>
#include <RobotIRremoteInt.h>
#define pi 3.14
#define ir1 16738455
#define ir2 16750695
#define ir3 16756815
#define ir4 16724175
#define ir5 16718055
#define ir6 16743045
#define ir7 16716015
#define ir8 16726215
#define ir9 16734885
#define ir0 16730805
#define irj 16732845
#define irx 16728765
#define longpress 4294967295
#define irok 16712445
#define left 16720605
#define right 16761405
#define down 16754775
#define up 16736925
using namespace std;
void laserSet(int,int,int);
void trans(float fa[], short int si[]);
void circle(short int x[], short int y[], float r);
void ellipse(short int x[], short int y[], float a, float b);
void heart(short x[], short y[], float a);
float serialIn(const char*);
void constout(short a[], short b[]);
void zoomout(short a[], short b[], float c);
void rotout(short a[], short b[], float c);
void rzout(short a[], short b[], float c, float d);
char irmode(int);
float irin(int,const char*);
short shape(const char* instream, int pin);
void t_ellipse(const char* instream, int pin, short x[], short y[]);
void t_circle(const char* instream, int pin, short x[], short y[]);
void t_heart(const char* instream, int pin, short x[], short y[]);
laser.cpp如下:
#include "laser.h"
void laserSet(int xpin,int ypin,int kpin) {
TCCR1B = TCCR1B & 0b11111000 | 1;//调整系统时钟
pinMode(xpin, OUTPUT);//x 连9
pinMode(ypin, OUTPUT);//y 连10
pinMode(kpin, OUTPUT); //laser on/off,连4
pinMode(13, OUTPUT);
digitalWrite(kpin, LOW);//关闭激光输出
digitalWrite(13, LOW);
Serial.begin(115200);
while (Serial.read() > 0);
}
void trans(float fa[], short int si[]) {//将浮点数据转为整形(0-255)
for (int i = 0; i < 9