Four Letter Word generator based on an associative word dictionary.
Dependencies: _24LCXXX
Dependents: vfd_modular_clock_mbed
Four Letter Word generator based on an associative word dictionary.
Needs an EEPROM to function (can be programmed onto a 24LC512 I2C EEPROM, or available as a pre-programmed add-on board)
Comes with a censored mode that removes expletives as well as a fully uncensored mode.
For details see:
Diff: flw.h
- Revision:
- 0:4d3dec05a4b7
- Child:
- 2:ff0163bc298d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flw.h Tue Feb 10 09:53:03 2015 +0000 @@ -0,0 +1,59 @@ +/* + * Four Letter Word Generator + * (C) 2015 Akafugu Corporation + * + * This program is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + */ + +#ifndef FLW_H__ +#define FLW_H__ + +#include <inttypes.h> +#include <stdbool.h> + + +#include "_24LCXXX.h" + +class FourLetterWord +{ +private: + _24LCXXX _24lc; + bool m_censored; + unsigned long m_offset; + char m_current_word[6]; + uint32_t m_lfsr; + + uint32_t randomize(); + + void rot13(char* w); + bool binary_search(const char *key, int imin, int imax); + uint8_t read_byte(unsigned int addr); + void read_buffer(unsigned int addr, uint8_t *buffer, int length); + + char* get_word_censored(); + char* get_word_uncensored(); + +public: + FourLetterWord(I2C *i2c, uint8_t addr = 0x50) : + _24lc(i2c, addr), + m_censored(true), + m_offset(0), + m_lfsr(0xbeefcace) {} + + void begin(uint32_t seed = 0xbeefcace, bool censored = true); + + void setCensored(bool c) { m_censored = c; } + + bool hasEeprom(); + char* getWord(); +}; + +#endif \ No newline at end of file