switch (val.toString) {
case "Monday":
I2C1.writeTo(i2c_address,[0x03, (dec2bcd(1))]);
break;
case "Tuesday":
I2C1.writeTo(i2c_address,[0x03, (dec2bcd(2))]);
break;
case "Wednesday":
I2C1.writeTo(i2c_address,[0x03, (dec2bcd(3))]);
break;
case "Thursday":
I2C1.writeTo(i2c_address,[0x03, (dec2bcd(4))]);
break;
case "Friday":
I2C1.writeTo(i2c_address,[0x03, (dec2bcd(5))]);
break;
case "Saturday":
I2C1.writeTo(i2c_address,[0x03, (dec2bcd(6))]);
break;
case "Sunday":
I2C1.writeTo(i2c_address,[0x03, (dec2bcd(7))]);
break;
default:
print(text,"Not a valid day");
return;
}
What about:
var days = ["Monday","Tuesday",...];
var idx = days.indexOf(val);
if (idx<0) {
print("Not a valid day");
} else {
I2C1.writeTo(i2c_address,[0x03, (dec2bcd(1+idx))]);
}
}
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Looks good! Just a suggestion but instead of:
What about:
It's maybe a bit more compact...