video corpo
Add to favorites

#Product Trends

Snack Machine Based on T5L Smart Screen

[Open Source Award Case]

Good day everyone! Today, we're excited to present an award-winning open-source case from the DWIN Developer Forum: Snack Machine Based on T5L Smart Screen. This solution leverages the T5L chip to achieve real-time control of claw grip force and speed via the PWM interface. It supports functions like reading long-press durations of background buttons, self-check for each module, error alerts, and synchronous display of coin insertion counts, game countdowns, etc. It also enables parameter settings for coin-to-credit ratios, game modes, multi-language interfaces, and grip force thresholds.

(1) Communication Code Between T5L Smart Screen and Main Controller
void uart2_master_isr() interrupt 4 {
u8 res;
if(RI0) {
RI0 = 0;
res = SBUF0;
uart2_rx_timeout = UART2_RX_TIMEOUT;
if((uart2_rx_sta&UART2_PACKET_OK)==0) {
if(step==0) {
recv_len = 0;
if(res==0x15) step = 1;
} else if(step==1) {
date_len = res;
step = 2;
if(date_len>UART2_PACKET_MAX_LEN) step = 0;
} else if(step==2) {
if(recv_len==date_len) {
step = 0;
if(res==0x16) {
uart2_rx_sta = date_len;
uart2_rx_sta |= UART2_PACKET_OK;
}
} else {
uart2_buf[recv_len++] = res;
}
}
}
}
}
(2) Motor Driver Code
void motor_move(MOTOR motor, MOTOR_DIR dir) {
if (motor == MOTOR_Z) { // Z-axis claw motor
if (dir == MOTOR_DIR_NONE) { // Stop
MOTOR_Z_DISABLE();
} else {
if ((IS_MOTOR_Z_BACKWARD_POS() && dir == MOTOR_DIR_BACKWARD) ||
(IS_MOTOR_Z_FORWARD_POS() && dir == MOTOR_DIR_FORWARD)) {
MOTOR_Z_DISABLE();
dir = MOTOR_DIR_NONE;
} else {
MOTOR_Z_ENABLE();
MOTOR_Z_DIR_PIN = (dir == MOTOR_DIR_BACKWARD);
}
}
} else if (motor == MOTOR_X) { // X-axis movement motor
// Similar logic for X-axis with position checks
} else if (motor == MOTOR_Y) { // Y-axis movement motor
// Similar logic for Y-axis with position checks
} else if (motor == MOTOR_CLAW) { // Claw motor
if (dir == MOTOR_DIR_NONE) {
MOTOR_CLAW_RELEASE(); // Release claw
} else {
MOTOR_CLAW_HOLD(); // Hold objects
}
}
}
(3) PWM-Based Claw Force and Speed Adjustment
const u16 MOTOR_DUTY[MOTOR_TOTAL][MOTOR_SPEED_MAX+1] = {
{45+DUTY_OFFSET, ...}, // X-axis speeds
{45+DUTY_OFFSET, ...}, // Y-axis speeds
{45, 60, ...}, // Z-axis speeds (no offset)
{200, 220, ...}, // Claw force levels
};

void motor_set_speed(MOTOR motor, u8 speed) {
if(speed>MOTOR_SPEED_MAX) return;
pwm_set_duty((PWM_CH)motor, MOTOR_DUTY[motor][speed]);
}

void motor_set_claw_strength_by_vol(float vol) {
#define CLAW_DUTY_MIN 200
#define CLAW_DUTY_MAX TIM_ARR
u16 duty;
vol = (vol - QZLDY_MIN) / (QZLDY_MAX - QZLDY_MIN); // Normalize voltage
if(vol<0)
vol = 0;
else if(vol>1)
vol = 1
duty = (u16)(vol * (CLAW_DUTY_MAX - CLAW_DUTY_MIN) + 0.5f) + CLAW_DUTY_MIN;
pwm_set_duty(PWM_CH_MOTOR_CLAW, duty);
}
(4) Long-Press Detection for Manufacturer Backend Buttons
u8 key_check_long_press(KEY key, u32 time) {
while(1) {
if(!(KEY_Scan(1) & key)) return 1; // Key released: failure
if(time) {
sys_delay_ms(1);
time--;
if(time==0) return 0; // Timeout: success
}
}
}

Details

  • Hunan, China
  • Beijing DWIN Technology Co., Ltd.