Commit e63dac72 authored by Alan Marchiori's avatar Alan Marchiori
Browse files

added change ardiuno code

parent a0b7b2e4
#include <LiquidCrystal.h>
#include <stdio.h>
LiquidCrystal lcd(8,9,4,5,6,7);
struct change{
int quarters;
int dimes;
int nickels;
int pennies;
};
struct change *make_change(float amount)
{
int cents = amount * 100;
struct change *c = (struct change *)malloc(sizeof(*c));
c->quarters = 0;
c->dimes = 0;
c->nickels = 0;
c->pennies = 0;
while (cents > 0){
if (cents >= 25) {
c->quarters++;
cents -= 25;
} else if (cents >= 10) {
c->dimes++;
cents -= 10;
} else if (cents >= 5) {
c->nickels++;
cents -= 5;
} else {
c->pennies = cents;
cents = 0;
}
}
return c;
}
void sprint_change(char* line1, char* line2, struct change* c)
{
sprintf(line1, "%3d qtr, %d dme",
c->quarters, c->dimes);
sprintf(line2, "%3d nkl, %d pny",
c->nickels, c->pennies);
}
void setup() {
lcd.begin(16,2);
lcd.setCursor(0,0);
}
void loop() {
static float amount = 0.0;
char line1[30], line2[30];
struct change *c = make_change(amount);
amount += 0.01;
sprint_change(line1, line2, c);
lcd.clear();
lcd.setCursor(0,0);
lcd.write(line1);
lcd.setCursor(0,1);
lcd.write(line2);
free(c);
delay(500);
}
#include <LiquidCrystal.h>
#include <stdio.h>
static FILE uartout = {0};
LiquidCrystal lcd(8,9,4,5,6,7);
static int uart_putchar(char c, FILE *stream)
{
Serial.write(c);
return 0;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
fdev_setup_stream(&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE);
stdout = &uartout;
printf("startup\n");
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.write("hello");
}
void loop() {
// put your main code here, to run repeatedly:
printf ("hello\n");
delay(500);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment