0% found this document useful (0 votes)
6 views9 pages

Program CES

This document contains an Arduino program for a cranial electrotherapy stimulator that utilizes an I2C LCD display and PWM for LED control. It allows users to set the frequency and duration of the stimulation through button inputs. The program includes functions for initializing the LCD, setting frequency and time, and running the stimulation process.

Uploaded by

Muhammad Asrul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views9 pages

Program CES

This document contains an Arduino program for a cranial electrotherapy stimulator that utilizes an I2C LCD display and PWM for LED control. It allows users to set the frequency and duration of the stimulation through button inputs. The program includes functions for initializing the LCD, setting frequency and time, and running the stimulation process.

Uploaded by

Muhammad Asrul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Bahasa pemograman

#include<wire.h>

#include <liquidcrystal_i2c.h> //i2c lcd library

#include <pwm.h>

#include <string.h>

liquidcrystal_i2c lcd(0x3f, 16, 2);

char judul_modul[] = { "cranial electrotherapy stimulator " };

//judul alat

int led = 9; // the pin that the led is attached to

int fadeamount = 127; // duty cycle

int32_t frequency = 10; // frequency (in hz)

int btup = 2; // tombol up

int btdown = 3; // tombol down

int btok = 4; //tombol ok/start

int btset = 5; // tombol set

int waktu = 10; // setting waktu pertama kali

int btupx, btdownx, btsetx, btokx;

int nilaifrek, nilaiwaktu;

int detik;

void setup() {

lcd.begin();
lcd.clear();

Icd.nocursor();

lcd.initial); //initialize all timers except for 0, to save time keeping functions

inittimerssafe();

// Serial.begin(9600);

//sets the frequency for the specified pin

bool success SetPinFrequencySafe(led, frequency);

//if the pin frequency was set successfully, turn pin 13 on

if(success) {

pwmWrite(led, frequency); }

pinMode(btup, INPUT_PULLUP);

pinMode(btdown, INPUT_PULLUP);

pinMode(btok, INPUT_PULLUP); pinMode(btset, INPUT_PULLUP);

pwmWrite(led, 0);

void loop() {

btupx = digitalRead(btup);

btdownx = digitalRead(btdown);

btokx = digitalRead(btok);

btsetx = digitalRead(btset);

lcd.setCursor(0,0);

lcd.print("CE STIMULATOR ");

lcd.setCursor(0,1);
lcd.print("SET");

pwmWrite(led, 0);

if(btsetx == LOW){

delay(200);

lcd.clear();

setfrek();

delay(1000);

lcd.clear();

settime();

delay(1000);

lcd.clear();

mulai();

void setfrek(){

btupx = digitalRead(btup);

btdownx = digitalRead(btdown);

btokx = digitalRead(btok);

btsetx = digitalRead(btset);

lcd.setCursor(0,0);

lcd.print("PILIH FREKUENSI: ");

lcd.setCursor(0,1);

lcd.print(frequency);
lcd.print(" ");

lcd.setCursor(5,1);

lcd.print("Hz");

if(frequency < 1){

frequency = 1;

if(frequency > 13){

frequency = 13;

if(btupx == LOW){

delay(200);

frequency++;

if(btdownx == LOW){

delay(200);

frequency--;

if(btokx == LOW){

delay(200);

nilaifrek frequency;

return; }
setfrek();

void settime(){

btupx = digitalRead(btup);

btdownx = digitalRead(btdown);

btokx = digitalRead(btok);

btsetx = digitalRead(btset);

lcd.setCursor(0,0);

lcd.print("PILIH WAKTU: ");

lcd.setCursor(0,1);

lcd.print(waktu);

lcd.print(" ");

lcd.setCursor(5,1);

lcd.print("Menit");

if(waktu < 1){

waktu = 1;

if(waktu > 30){

waktu = 30;

}
if(btupx == low){

delay(200);

waktu++;

if(btdownx == low){

delay(200);

waktu--;

if(btokx == low){

delay(200); nilaiwaktu waktu;

return;

settime();

void mulai(){

lcd.setcursor(0,0);

lcd.print("frekuensi= ");

lcd.print(nilaifrek);

lcd.setcursor(14,0);

lcd.print("hz");

lcd.setcursor(0,1);

lcd.print(nilaiwaktu);

lcd.print(":");

lcd.print(detik);
lcd.print(" ");

pwmwrite(led, fadeamount);

setpinfrequencysafe(led, nilaifrek);

btokx = digitalread(btok);

detik--;

if(btokx == low){

delay(400);

nilaiwaktu = 0;

detik = 0;

lcd.clear();

return; }

if((nilaiwaktu 1)&&(detik < 1)){

delay(1000);

nilaiwaktu = 0;

detik = 0;

lcd.clear(); return; }

if(detik < 1){

nilaiwaktu--;

detik = 59;

if(btsetx == low){
delay(200);

lcd.clear();

return; }

delay(1000);

mulai();

void lcdinitial() {

int lcd_number = 16;

int speeddelay = 500;

unsigned int l, m, n;

Unsigned int data_len = strlen(judul_modul);

lcd.clear();

lcd.setcursor(0, 0);

lcd.print(" judul modul ");

for (1 lcd_number; 1 >= 0; --1) {

if (1> lcd_number)break;

lcd.setcursor(1, 1);

for (m = 0; m<(lcd_number - 1); m++) {

lcd.print(judul_modul[m]);

delay(speeddelay); //ubah untuk kecepatan pergeseran text

n = 0;

for (10;1<= data_len; 1++) {


n++;

lcd.setcursor(0, 1);

for (m= 0; m<16; m++) {

if (judul_modul[m + n] == null) {

return;

lcd.print(judul_modul[m + n]);

delay(speeddelay); //ubah untuk kecepatan pergeseran text (samakan sama yang diatas)

lcd.clear();

You might also like