Skip to content

Instantly share code, notes, and snippets.

@kachurovskiy
kachurovskiy / h4.ino
Created February 12, 2024 06:27
Pre-release version of NanoEls H4 V12 with hardware pulse counter
// https://github.com/kachurovskiy/nanoels
/* Change values in this section to suit your hardware. */
// Define your hardware parameters here.
const int ENCODER_PPR = 600; // 600 step spindle optical rotary encoder. Fractional values not supported.
const int ENCODER_BACKLASH = 3; // Numer of impulses encoder can issue without movement of the spindle
// Spindle rotary encoder pins. Swap values if the rotation direction is wrong.
#define ENC_A 7
// https://github.com/kachurovskiy/nanoels
/* Change values in this section to suit your hardware. */
// Define your hardware parameters here.
const int ENCODER_STEPS_INT = 600; // 600 step spindle optical rotary encoder. Fractional values not supported.
const int ENCODER_BACKLASH = 3; // Numer of impulses encoder can issue without movement of the spindle
// Spindle rotary encoder pins. Swap values if the rotation direction is wrong.
#define ENC_A 7
const int potPin = A0;
const int enaPin = 4;
const int dirPin = 5;
const int stepPin = 6;
const int fwdPin = 12;
const int revPin = 11;
const int maxSpeed = 700; // RPM
const int stepsPerRevolution = 200;
const int minPotValue = 20; // Minimum pot value to start the motor
#include <SPI.h>
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(21, 48, 47, 38, 39, 40, 41, 42, 2, 1);
void setup() {
lcd.begin(20, 4);
lcd.setCursor(0, 3);
}
#define STEP 12
#define ENA 13
// How fast we want to accelerate the stepper. Reasonable values 5 - 200.
#define ACCELERATION 5
// Time between the STEP pulses when starting slow. 400 pulses per second.
#define DELAY_US_MAX 2500
// Time between the STEP pulses at highest speed. 25*400 pulses per second.
#define DELAY_US_MIN 100
// Maximum size of the acceleration table. Arduino has little memory.
#define STEP 12
void setup() {
// 200 step per revolution motor driver on this pin.
pinMode(STEP, OUTPUT);
}
void topSpeed_1Turn() {
for (int i = 0; i < 200; i++) {
// Issue 1 step.
@kachurovskiy
kachurovskiy / NanoElsH2.ino
Created January 6, 2021 12:25
NanoEls 2-axis version [BUGGY] [DO NOT USE]
// https://github.com/kachurovskiy/nanoels
/* Change values in this section to suit your hardware. */
// Define your hardware parameters here. Don't remove the ".0" at the end.
#define ENCODER_STEPS 600.0 // 600 step spindle optical rotary encoder
#define MOTOR_STEPS 200.0 // 200 step stepper motor, no microstepping
#define LEAD_SCREW_HMM 200.0 // 2mm lead screw
#define MOTOR_X_STEPS 200.0 // 200 step stepper motor, no microstepping
package com.slowvideoc;
import com.arthenica.mobileffmpeg.Config;
import com.arthenica.mobileffmpeg.FFmpeg;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
#include <avr/sleep.h>
#include <avr/wdt.h>
void setup() {
pinMode(4, OUTPUT);
}
void water(int ms) {
digitalWrite(4, HIGH);
delay(ms);
@kachurovskiy
kachurovskiy / ClapLED.ino
Last active January 8, 2018 22:45
Double-clap to toggle the light. https://youtu.be/0-Un6Gu4Ah0
bool isOn = false;
void setup() {
pinMode(2, OUTPUT);
digitalWrite(2, isOn ? HIGH : LOW);
}
int th = 40;
void toggle() {