1976浏览
查看: 1976|回复: 7

激光切割+编程 时针

[复制链接]
一个会转动的时钟,上面会坐一个小人,旁边摆个小桌子。每过一段时间,小人就会转走来提醒程序员该休息了。

激光切割+编程 时针图1
Clockwork
Spring 2015
Alex Greenspan
Greta Gardner
Andy Mah


Column 1 Column 2 Column 3
激光切割+编程 时针图2 激光切割+编程 时针图3 激光切割+编程 时针图4
激光切割+编程 时针图5 激光切割+编程 时针图6 激光切割+编程 时针图7
激光切割+编程 时针图8 激光切割+编程 时针图9 激光切割+编程 时针图10
#include <Servo.h>  // servo library

// LIGHT SENSOR RELATED VARIABLES
const int sensorPin = 0; // Light sensor in A0
int prevLightLevel = 1023; // global variable for previous light level
int lightLevel; // global variable for light level
const int midLight = 400; // make 200 for normal use, 400 for testing

// SERVO RELATED VARIABLES
Servo servo; // servo control object
int startAngle;
int currentAngle;
int angleHigh;
int angle = 0;
const int angleStep = 10; // number of angles to rotate per loop
const int highestAngle = 180;
const int lowestAngle = 30; // adjusted for backward rotate

// TIME RELATED VARIABLES
unsigned long startTime; // start time
unsigned long elapsedTime; // elapsed time

void setup()
{  
  servo.attach(9); // begin sending control signals to the servo
  servo.write(lowestAngle); // start servo at the lowest angle
  Serial.begin(9600); // for testing purposes
}

void loop()
{
  lightLevel = analogRead(sensorPin); // check if someone is sitting
  // Serial.println(lightLevel); // print light level
  // delay(1000);

  if (lightLevel <= midLight && prevLightLevel > midLight) { // just started sitting AKA SETUP
    //Serial.println("GET HERE");
    startTime = millis(); // start the timer
    currentAngle = lowestAngle; // make sure currentAngle is given a number -> lowest angle
    Serial.println("Begin sitting at starting position");

  } else if (lightLevel <= midLight && prevLightLevel <= midLight) { // still sitting AKA ACTIVE
    elapsedTime = millis() - startTime; // clock the elapsed time since started sitting
    if (elapsedTime % (1000*5) == 0) { // 5 seconds passed, time to rotate
      // Usually prints three of the below at once, so make sure it rotates less to account for it
      forward_rotate();
      //Serial.println("current angle is " + currentAngle);
    }

  } else { // finished sitting
    //Serial.println(currentAngle);
    if (currentAngle != lowestAngle) {
      backward_rotate();
    }
  }

  prevLightLevel = lightLevel; // update prev light level to current light level
}

void forward_rotate()
{
  if (angleStep + currentAngle < highestAngle) {
    angleHigh = angleStep + currentAngle;
  } else {
    angleHigh = highestAngle;
  }
  for(angle = currentAngle; angle < angleHigh; angle++)  
  {                                  
    servo.write(angle);               
    delay(30); // used to be 15                 
  } 
  currentAngle = angleHigh;
  Serial.print("Current angle is: ");
  Serial.println(currentAngle);
  Serial.println(lightLevel);
}

void backward_rotate()
{
  Serial.println(lightLevel);
  for(angle = currentAngle; angle > lowestAngle; angle--)    
  {                                
    servo.write(angle);           
    delay(60); // used to be 15      
  } 
  currentAngle = lowestAngle; // reset currentAngle
  Serial.println("Reset back to starting position");
}


激光切割+编程 时针图10

原文:https://www.hackster.io/alexsg/clockwork-82a828

 初级技匠

发表于 2022-5-8 10:10:03

有视频演示吗?
回复

使用道具 举报

三春牛-创客  初级技神

发表于 2023-8-4 22:40:51

厉害厉害
回复

使用道具 举报

三春牛-创客  初级技神

发表于 2023-8-4 22:41:53

赞赞赞赞赞!
回复

使用道具 举报

三春牛-创客  初级技神

发表于 2023-8-4 22:43:01

有视频演示吗?有的话就更好了。
回复

使用道具 举报

花生编程  中级技匠

发表于 2023-8-5 22:21:56

厉害厉害
回复

使用道具 举报

花生编程  中级技匠

发表于 2023-8-5 22:23:04

赞赞赞!它是怎么运行的啊?
回复

使用道具 举报

花生编程  中级技匠

发表于 2023-8-5 22:24:08

有演示的视频看吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail