diy激光投影,问题出在哪不清楚了
/*LaserText v1.1 by Ben Makes Everything
* https://youtu.be/u9TpJ-_hBR8
* This fixes many issues from the first version and provides much better spacing on the text
*/
#include <PGMWrap.h>
#include <SoftwareSerial.h>
#include <util/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>
SoftwareSerial mySerial(8, 9); // RX, TX
//Timing stuff - NOP = 1 clock cycle
//NOP=1个时钟周期
//asm(nop);具体延时
#define NOP __asm__ __volatile__ ("nop\n\t")
#define LetterSpace __asm__ __volatile__ ("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t")
int mirrorPin = 3; //Mirror tab counter sensor
int revPin = 2; //Revolution tab counter sensor
int laserPin = 6;// Laser output
/*for reference:
7-6-5-4-3-2-TX-RX (Port D)
PORTD = B01000000; // sets digital pin 6 HIGH
*/
volatile int mirrorFlag = 0; //Counts how many mirrors have passed lower sensor统计有多少后视镜经过下部传感器
int mirrorFlagOld = 0; //stores previous value of mirror flag
int centerVal = 1800; //Left/right adjustment
int avgWidth = 36;
const byte numChars = 32; //MAX characters value
char myData; // an array to store the received data用于存储接收到的数据的数组
boolean newData = false; // for checking serial
const int rows = 12; //Define rows (should be same as # of mirrors)
const int columns = 9; //Defines number of line segments定义线段的数量
int mCount = 0; //message length counter
//These are the Characters that can be displayed represented as 2D array
const int space[ rows ][ columns ] PROGMEM = { //Space bar
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
};
const int a[ rows ][ columns ] P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 1, 1, 1, 0, 0}
};
const int t[ rows ][ columns ] PROGMEM = {
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0}
};
const int u[ rows ][ columns ] PROGMEM = {
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 1, 0, 0, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 1, 0}
};
const int v[ rows ][ columns ] PROGMEM = {
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 1, 0, 0, 1, 1, 1},
{0, 1, 1, 0, 0, 1, 1, 0},
{0, 1, 1, 0, 0, 1, 1, 0},
{0, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0}
};
const int w[ rows ][ columns ] PROGMEM = {
{1, 1, 0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0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 0, 0, 0},
{0, 1, 1, 1, 0, 0, 0, 0},
{1, 1, 1, 0, 0, 0, 0, 0},
{1, 1, 0, 0, 0, 0, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1}
};
const int zero[ rows ][ columns ] PROGMEM = {
{0, 0, 1, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 0, 0, 1, 1, 1},
{1, 1, 0, 0, 1, 1, 1, 1},
{1, 1, 0, 0, 1, 0, 1, 1},
{1, 1, 0, 1, 1, 0, 1, 1},
{1, 1, 0, 1, 1, 0, 1, 1},
{1, 1, 0, 1, 0, 0, 1, 1},
{1, 1, 1, 1, 0, 0, 1, 1},
{1, 1, 1, 0, 0, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 1, 0, 0}
};
const int one[ rows ][ columns ] PROGMEM = {
{0, 0, 0, 0, 1, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1}
};
const int two[ rows ][ columns ] PROGMEM = {
{0, 1, 1, 1, 1, 1, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 0},
{1, 1, 0, 0, 0, 1, 1, 1},
{0, 0, 0, 0, 0, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 0, 0, 0},
{0, 1, 1, 1, 0, 0, 0, 0},
{1, 1, 1, 0, 0, 0, 0, 0},
{1, 1, 0, 0, 0, 0, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1}
};
const int three[ rows ][ columns ] PROGMEM = {
{0, 1, 1, 1, 1, 1, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 0},
{1, 1, 0, 0, 0, 1, 1, 1},
{0, 0, 0, 0, 0, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 1, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 1, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 0},
{0, 1, 1, 1, 1, 1, 0, 0}
};
const int four[ rows ][ columns ] PROGMEM = {
{0, 0, 0, 0, 0, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 1, 1},
{0, 0, 0, 1, 1, 1, 1, 1},
{0, 0, 1, 1, 1, 0, 1, 1},
{0, 1, 1, 1, 0, 0, 1, 1},
{1, 1, 1, 0, 0, 0, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1}
};
const int five[ rows ][ columns ] PROGMEM = {
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 0, 0, 0, 0, 0, 0},
{1, 1, 0, 0, 0, 0, 0, 0},
{1, 1, 1, 1, 1, 1, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 0, 0, 0, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 0},
{0, 1, 1, 1, 1, 1, 0, 0}
};
const int six[ rows ][ columns ] PROGMEM = {
{0, 0, 1, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 0, 0, 0, 0, 0},
{1, 1, 0, 0, 0, 0, 0, 0},
{1, 1, 0, 1, 1, 1, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 0, 0, 1, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 1, 0, 0, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 1, 0, 0}
};
const int seven[ rows ][ columns ] PROGMEM = {
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 0, 0, 0},
{0, 1, 1, 1, 0, 0, 0, 0},
{1, 1, 1, 0, 0, 0, 0, 0},
{1, 1, 0, 0, 0, 0, 0, 0},
{1, 1, 0, 0, 0, 0, 0, 0}
};
const int eight[ rows ][ columns ] PROGMEM = {
{0, 1, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 0, 0, 1, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{0, 1, 1, 0, 0, 1, 1, 0},
{0, 0, 1, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 1, 0, 0},
{0, 1, 1, 0, 0, 1, 1, 0},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 1, 0, 0, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 1, 0}
};
const int nine[ rows ][ columns ] PROGMEM = {
{0, 0, 1, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 0, 0, 1, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 1, 0, 0, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 0, 1, 1, 1, 1, 0},
{0, 0, 0, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 0, 0, 0},
{0, 1, 1, 1, 0, 0, 0, 0},
{1, 1, 1, 0, 0, 0, 0, 0}
};
const int per[ rows ][ columns ] PROGMEM = {//period
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0}
};
const int comma[ rows ][ columns ] PROGMEM = {//period
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 1, 1, 0, 0, 0, 0},
{0, 1, 1, 0, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 0, 0, 0}
};
const int sc[ rows ][ columns ] PROGMEM = { //semicolon
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
};
const int exc[ rows ][ columns ] PROGMEM = { //exclamation
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0}
};
const int ques[ rows ][ columns ] PROGMEM = { //question mark
{0, 0, 1, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 0, 0, 1, 1, 1},
{1, 1, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 1, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0}
};
const int checker[ rows ][ columns ] PROGMEM = { //question mark
{1, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 1, 0, 1}
};
const int block[ rows ][ columns ] PROGMEM = { //question mark
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1}
};
int pulses[ rows ][ columns ];
void setup() {
Serial.begin(9600);
mySerial.begin(38400);
pinMode(mirrorPin, INPUT_PULLUP); //Mirror counter
pinMode(revPin, INPUT_PULLUP); //Full rotation counter
pinMode(laserPin, OUTPUT); //Laser configured as output
attachInterrupt(digitalPinToInterrupt(mirrorPin), ISR_mirror, RISING);
attachInterrupt(digitalPinToInterrupt(revPin), ISR_rev, RISING);
}
void loop() {
receiveData();
showNewData();
determineMirror();
}
void ISR_mirror() {
mirrorFlag++;
//Serial.println(mirrorFlag);//光电传感器计数测试
}
void ISR_rev() {
mirrorFlag = 0;
}
//The first value after nopTimer has to be set manually for each mirror - software left/right alignment
void determineMirror() {
if (mirrorFlag != mirrorFlagOld) {
mirrorFlagOld = mirrorFlag;
switch (mirrorFlag) {
case 1:
nopTimer((centerVal - strlen(myData)*avgWidth));
encodePulses(0);
break;
case 2:
nopTimer(49 + centerVal - (strlen(myData)*avgWidth));
encodePulses(1);
break;
case 3:
nopTimer(85 + centerVal - (strlen(myData)*avgWidth));
encodePulses(2);
break;
case 4:
nopTimer(57 + centerVal - (strlen(myData)*avgWidth));
encodePulses(3);
break;
case 5:
nopTimer(-24 + centerVal - (strlen(myData)*avgWidth));
encodePulses(4);
break;
case 6:
nopTimer(9 + centerVal - (strlen(myData)*avgWidth));
encodePulses(5);
break;
case 7:
nopTimer(15 + centerVal - (strlen(myData)*avgWidth));
encodePulses(6);
break;
case 8:
nopTimer(122 + centerVal - (strlen(myData)*avgWidth));
encodePulses(7);
break;
case 9:
nopTimer(58 + centerVal - (strlen(myData)*avgWidth));
encodePulses(8);
break;
case 10:
nopTimer(98 + centerVal - (strlen(myData)*avgWidth));
encodePulses(9);
break;
case 11:
nopTimer(38 + centerVal - (strlen(myData)*avgWidth));
encodePulses(10);
break;
case 12:
nopTimer(10 + centerVal - (strlen(myData)*avgWidth));
encodePulses(11);
break;
}
}
}
//This function turns the laser on and off based on what serial data comes in
//此功能根据输入的串行数据打开和关闭激光
void encodePulses(int mirrorNum) {
noInterrupts(); //disables interrupts for better timing禁用中断以获得更好的定时
mCount = strlen(myData) - 1; //sets length to serial data length, -1 just removes junk end character from string
//将长度设置为串行数据长度,-1只是从字符串中删除垃圾结束字符
while (mCount > -1) {
int segment = 7;
while (segment > -1) { //reads right to left because the motor spins CCW :(
switch (myData) {
case ' ':
pulses = pgm_read_dword_near(&space);
break;
case '/':
pulses = pgm_read_dword_near(&checker);
break;
case '|':
pulses = pgm_read_dword_near(&block);
break;
case 'a':
pulses = pgm_read_dword_near(&a);
break;
case 'b':
pulses = pgm_read_dword_near(&b);
break;
case 'c':
pulses = pgm_read_dword_near(&c);
break;
case 'd':
pulses = pgm_read_dword_near(&d);
break;
case 'e':
pulses = pgm_read_dword_near(&e);
break;
case 'f':
pulses = pgm_read_dword_near(&f);
break;
case 'g':
pulses = pgm_read_dword_near(&g);
break;
case 'h':
pulses = pgm_read_dword_near(&h);
break;
case 'i':
pulses = pgm_read_dword_near(&i);
break;
case 'j':
pulses = pgm_read_dword_near(&j);
break;
case 'k':
pulses = pgm_read_dword_near(&k);
break;
case 'l':
pulses = pgm_read_dword_near(&l);
break;
case 'm':
pulses = pgm_read_dword_near(&m);
break;
case 'n':
pulses = pgm_read_dword_near(&n);
break;
case 'o':
pulses = pgm_read_dword_near(&o);
break;
case 'p':
pulses = pgm_read_dword_near(&p);
break;
case 'q':
pulses = pgm_read_dword_near(&q);
break;
case 'r':
pulses = pgm_read_dword_near(&r);
break;
case 's':
pulses = pgm_read_dword_near(&s);
break;
case 't':
pulses = pgm_read_dword_near(&t);
break;
case 'u':
pulses = pgm_read_dword_near(&u);
break;
case 'v':
pulses = pgm_read_dword_near(&v);
break;
case 'w':
pulses = pgm_read_dword_near(&w);
break;
case 'x':
pulses = pgm_read_dword_near(&x);
break;
case 'y':
pulses = pgm_read_dword_near(&y);
break;
case 'z':
pulses = pgm_read_dword_near(&z);
break;
case '0':
pulses = pgm_read_dword_near(&zero);
break;
case '1':
pulses = pgm_read_dword_near(&one);
break;
case '2':
pulses = pgm_read_dword_near(&two);
break;
case '3':
pulses = pgm_read_dword_near(&three);
break;
case '4':
pulses = pgm_read_dword_near(&four);
break;
case '5':
pulses = pgm_read_dword_near(&five);
break;
case '6':
pulses = pgm_read_dword_near(&six);
break;
case '7':
pulses = pgm_read_dword_near(&seven);
break;
case '8':
pulses = pgm_read_dword_near(&eight);
break;
case '9':
pulses = pgm_read_dword_near(&nine);
break;
case ':':
pulses = pgm_read_dword_near(&sc);
break;
case '.':
pulses = pgm_read_dword_near(&per);
break;
case ',':
pulses = pgm_read_dword_near(&comma);
break;
case '!':
pulses = pgm_read_dword_near(&exc);
break;
case '?':
pulses = pgm_read_dword_near(&ques);
default:
pulses = pgm_read_dword_near(&space);
break;
}
//laser on/off for specified intervals
if (pulses > 0) {
PORTD = B01000000; // sets digital pin 6 HIGH
//digitalWrite(laserPin,HIGH);
LetterSpace;
LetterSpace;
//Serial.println("x");
}
else {
PORTD = B00000000; // sets digital pin 6 LOW
//digitalWrite(laserPin,LOW);
LetterSpace;
LetterSpace;
}
segment--;
}
PORTD = B00000000; // sets digital pin 6 LOW
// digitalWrite(laserPin,LOW);
LetterSpace;
LetterSpace;
mCount--;
}
interrupts(); //reenable interrupts
}
void receiveData() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
myData = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
Serial.println(numChars);
}
}
else {
myData = '\0'; // terminate the string终止字符串
ndx = 0;
newData = true;
}
}
}
void showNewData() {
if (newData == true) {
newData = false;
}
}
//This is used instead of delayMicroseconds - more accurate这是用来代替延迟微秒-更准确
void nopTimer(int howLong) {
for (int t = 0; t < howLong; t++) {
NOP;
}
}
问题出在激光始终不出光
D6 接口 始终没有高电平输出
复位后 输入字符代码能跑到PORTD = B01000000;这行
外围硬件我都测试过了
PORTD = B01000000;
这段我也找相似的测试过 都能出光
国外大神的 一个激光文字投影
有兴趣的youtube搜索 diy laser
https://v.douyin.com/U4TR5Ko/这是我 下载的原视频.不完全的
页:
[1]