BASIC4MCU | 질문게시판 | 아두이노 코딩 질문드립니다.
페이지 정보
작성자 좋은일만 작성일2019-11-24 19:08 조회4,164회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=10869
본문
안녕하세요,제가 현재 아두이노를 이용해 자동블라인드를 만드려고 하는데요.
이 코딩문을 수정해서 만들고 싶은데 어떻게 해야할지 질문드립니다.
#include <MsTimer2.h> #include <AFMotor.h>#define PHOTOCELL 0#define STEP_PER_ONE_CYCLE 2048 // 1 cycle(360 degree) = 2048#define COUNT_PER_ONE_CYCLE 110#define STEP_PER_COUNT (STEP_PER_ONE_CYCLE/COUNT_PER_ONE_CYCLE)unsigned int gun_Count;unsigned int PhotocellValue[1][2] = {{0,0}};unsigned int gun_findPosition = 0;// Connect a stepper motor with 64 steps per revolution (5.625 degree)// to motor port #2 (M3 and M4)AF_Stepper motor(64, 2);void setup() {MsTimer2::set(100, ReadPhotocell);MsTimer2::start();Serial.begin(9600); // set up Serial library at 9600 bpsSerial.println("< Solar Tracking System >");// setSpeed(uint8_t s), 2^8*2 (0 ~ 511)// 1 rpm = 36motor.setSpeed(180); // 5 rpm// Stepper Motor Operation function// step(uint16_t steps, uint8_t dir, uint8_t style)// steps : 2^16*2 (0~131071)// dir : FORWARD, BACKWARD, BRAKE, RELEASE// style : SINGLE, DOUBLE, INTERLEAVE, MICROSTEP// "Single" means single-coil activation,// "double" means 2 coils are activated at once (for higher torque)motor.step(STEP_PER_ONE_CYCLE, FORWARD, DOUBLE);}void loop() {if (gun_Count>500) { // in 50 secgun_Count = 0;PhotocellValue[0][0] = 0;PhotocellValue[0][1] = 0;gun_findPosition = 0;motor.step(STEP_PER_ONE_CYCLE, FORWARD, DOUBLE);}if (gun_findPosition == 0) { // check position of lightif (PhotocellValue[0][0] != 0) {if (PhotocellValue[0][1] != 0) {int stepVal = STEP_PER_ONE_CYCLE-((PhotocellValue[0][1])*STEP_PER_COUNT);if(stepVal >= 0)motor.step(stepVal, BACKWARD, DOUBLE);elsemotor.step(STEP_PER_ONE_CYCLE, BACKWARD, DOUBLE);gun_findPosition = 1;}}}}void ReadPhotocell() {int lightVal = analogRead(PHOTOCELL);if (PhotocellValue[0][0] < lightVal) {PhotocellValue[0][0] = lightVal;PhotocellValue[0][1] = gun_Count;} gun_Count++;}이 코딩문에 대한 설명인데요,조도센서를 통해 일정시간마다 빛의 세기를 측정하여 가장 빛이 강한 곳을찾아서 모터를 돌아가게 하는 코드입니다.여기서 제가 수정하고 싶은 방향은 일정시간마다 빛의 세기를측정해서 특정값보다 크면 90도만큼 회전하였다가,특정값 아래로 떨어지면 다시 반대방향으로 90도만큼돌게 하고싶은데요,어떤식으로 수정을 해야할지 알려주시면 감사하겠습니다.
댓글 0
조회수 4,164등록된 댓글이 없습니다.