no message

master
zcy 2023-10-08 00:55:53 +08:00
parent 3edb55948a
commit 8209500190
2 changed files with 57 additions and 36 deletions

View File

@ -1,36 +0,0 @@
int incomedate = 0;
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
Serial.begin(9600); //设置串口波特率9600
Serial.println(78, BIN);// "1001110"
Serial.println(78, OCT);// "116"
Serial.println(78, DEC);// "78"
Serial.println(78, HEX);// "4E"
Serial.println(1.23456, 0);// "1"
Serial.println(1.23456, 2);// "1.23"
Serial.println(1.23456, 4);// "1.2346"
Serial.println('N');// "N"
Serial.println("Hello world.");// "Hello world."
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
if (Serial.available() > 0)//串口接收到数据
{
incomedate = Serial.read();//获取串口接收到的数据
if (incomedate == 'H')
{
Serial.println("Good Job!");
}
}
}

View File

@ -0,0 +1,57 @@
/*
Stepper Motor Control - one revolution
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
The motor should revolve one revolution in one direction, then
one revolution in the other direction.
Created 11 Mar. 2007
Modified 30 Nov. 2009
by Tom Igoe
*/
#include <Stepper.h>
#include <Servo.h>
const int stepsPerRevolution = 20; // change this to fit the number of steps per revolution
// for your motor
Servo myservo; // create servo object to control a servo
// initialize the stepper library on pins 8 through 11:
#define CLK 10
#define CW 9
#define EN 8
void setup() {
// set the speed at 60 rpm:
pinMode(CLK,OUTPUT);
pinMode(CW,OUTPUT);
pinMode(EN,OUTPUT);
// initialize the serial port:
Serial.begin(115200);
digitalWrite(EN,LOW);
myservo.attach(12); // attaches the servo on pin 9 to the servo object
}
void loop() {
char data[20] = {0};
digitalWrite(EN,LOW);
// step one revolution in one direction:
if(Serial.available()){ //if number of bytes (characters) available for reading from {
Serial.readBytes(data,20);
Serial.print("I received:"); //print I received
Serial.write(data); //send what you read
String strInt = data; // string to hold input
int ints = strInt.toInt();
Serial.print(ints); //print I received
myservo.write(ints); // sets the servo position according to the scaled value
for(int cnt = 0;cnt < ints;cnt++){
delay(100);
digitalWrite(EN,LOW);
delay(100);
digitalWrite(EN,HIGH);
}
ints = 0;
}
}