244 views|1 replies

70

Posts

1

Resources
The OP
 

【Follow me Season 2 Episode 1】Final episode [Copy link]

 This post was last edited by aramy on 2024-8-26 10:32

Preliminary tasks

【Follow me Season 2 Episode 1】Building the development environment and lighting up the LED lightshttps ://bbs.eeworld.com.cn/thread-1289781-1-1.html

【Follow me Season 2 Episode 1】Basic tasks 1, 2, 3https: //bbs.eeworld.com.cn/thread-1290634-1-1.html

Advanced task (must do): Make a tumbler - show the different lighting effects during the movement of the tumbler

The board integrates a motion sensor (LIS3DH 3-axis XYZ accelerometer) with tap and free fall detection functions. This means that the board can detect changes in acceleration, but there is no way to detect changes in angular velocity, and there is no way to detect the occurrence of rotation. The library function routine provides code for reading acceleration. By referring to the routine, it is easy to read the acceleration in three directions.

Place the board horizontally, the y direction is the direction of gravity, and there will be a gravitational acceleration of 9.8 in a static state. The X direction is the horizontal direction. Through the acceleration of the X and Y axis directions, the current inclination angle of the board can be calculated. By mapping the inclination angle to the color space and the number of LED lights, gorgeous LED lights at different angles can be obtained.

#include <Adafruit_CircuitPlayground.h>
#include <math.h>
#define PI 3.1415926

float MinTemp = 0.0, MaxTemp = 30.0, a, b, c, d;
float tempC;
uint16_t lightval;
void Getabcd()
{
  a = MinTemp + (MaxTemp - MinTemp) * 0.2121;
  b = MinTemp + (MaxTemp - MinTemp) * 0.3182;
  c = MinTemp + (MaxTemp - MinTemp) * 0.4242;
  d = MinTemp + (MaxTemp - MinTemp) * 0.8182;
}

// 浮点数转颜色  伪彩色
void GetColor(float val, uint8_t rgbval[])
{
  byte red = 0, green = 0, blue = 0;
  red = constrain(255.0 / (c - b) * val - ((b * 255.0) / (c - b)), 0, 255);
  if ((val > MinTemp) & (val < a))
  {
    green = constrain(255.0 / (a - MinTemp) * val - (255.0 * MinTemp) / (a - MinTemp), 0, 255);
  }
  else if ((val >= a) & (val <= c))
  {
    green = 255;
  }
  else if (val > c)
  {
    green = constrain(255.0 / (c - d) * val - (d * 255.0) / (c - d), 0, 255);
  }
  else if ((val > d) | (val < a))
  {
    green = 0;
  }

  if (val <= b)
  {
    blue = constrain(255.0 / (a - b) * val - (255.0 * b) / (a - b), 0, 255);
  }
  else if ((val > b) & (val <= d))
  {
    blue = 0;
  }
  else if (val > d)
  {
    blue = constrain(240.0 / (MaxTemp - d) * val - (d * 240.0) / (MaxTemp - d), 0, 240);
  }
  rgbval[0] = red;
  rgbval[1] = green;
  rgbval[2] = blue;
}

void setup()
{
  Serial.begin(115200);
  CircuitPlayground.begin();
  CircuitPlayground.strip.setBrightness(255);
  Getabcd();
}

void loop()
{
  uint8_t rgbval[3];
  float x, y, angle;
  x = CircuitPlayground.motionX();
  y = CircuitPlayground.motionY();
  angle = atan2(y, x) * 180 / PI;

  Serial.println(angle);
  GetColor(abs(angle)/2, rgbval);
  for (uint8_t i = 0; i < abs(angle)/4; i++)
    CircuitPlayground.strip.setPixelColor(i, rgbval[0], rgbval[1], rgbval[2]);
  CircuitPlayground.strip.show();
  delay(200);
  CircuitPlayground.strip.clear();
  // delay(200);
}

VID_20240825_085514

Creative Task 2: Squidward - Squidward's tentacles can expand or contract according to the size of the surrounding sound.

I bought a servo when I placed an order, and after receiving it, I found that this servo is different from the servos I see in daily life. Most of the servos I see in daily life are 180-degree servos, but this one is a 360-degree servo. The driving signal of the servos I used to contact was a 50Hz square wave, in which the high-level change from 0.5ms to 2.5ms corresponds to an angle of 0~180 degrees. The driving signal of this servo is also a 50Hz square wave, but 1.5ms corresponds to stop. 0.5ms~1.5ms corresponds to clockwise rotation, and 1.5ms~2.5ms corresponds to counterclockwise rotation. The closer the distance to 1.5ms, the slower the rotation speed, and the farther the distance, the faster the rotation speed. However, the rotation of a specified angle cannot be controlled, and the clockwise and counterclockwise rotation speeds are not equal. This makes it difficult to control the position of the servo cantilever well.

The microphone sound is collected here and simply mapped to the rotation of the servo to drive the rotation of the servo.

#include <Adafruit_CircuitPlayground.h>
#include <Servo.h> 
float value;
Servo myservo;

void setup() {
  Serial.begin(115200);
  CircuitPlayground.begin();
   myservo.attach(A1, 500, 2500); // 修正脉冲宽度
   myservo.writeMicroseconds(1500); // 停机
}

void loop() {
  // Take 10 milliseconds of sound data to calculate
  value = CircuitPlayground.mic.soundPressureLevel(10);
  
  Serial.print("Sound Sensor SPL: ");
  Serial.println(value-60);
  myservo.writeMicroseconds(1500+(value-65)*20); // 停机
  delay(20);
}

hw

20240826103241147.zip (487.14 KB, downloads: 1)

This post is from DigiKey Technology Zone

Latest reply

Thank you  Details Published on 2024-8-26 15:39
 
 

3

Posts

0

Resources
2
 
Thank you
This post is from DigiKey Technology Zone
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list